Skip to content

[WordPress] How to Get All Option Names in Option Group

When we developing the WordPress plugin, we can simply use register_setting(), get_option(), and update_option() function to store some plugin settings in the database.

But sometimes I wrote too many codes for testing, and building too many test data in database, and they are not used in the common runtime. I think I do some bad thing, waste the database space.

Fortunately, when creating the data field, different option groups were created according to different plugins and different functions. Today, I will record how to list all the option names in the same option group.


Get the option names in the specific option group

The following PHP code you can place anywhere you can print it out. Since there is no special function that can list all options under the specified option group, we must load the global variable $new_whitelist_options, and find the group name we named.

For example, my option group name is tnt-settings-group (but I forgot what is tnt…), then I can print all the option field:

global $new_whitelist_options;
$option_names = $new_whitelist_options[ 'tnt-settings-group' ];
echo json_encode( $option_names );


Output:

["event_name","ca_reserve_list"]


It seems that I set fewer options than I thought, which is also a good thing.


References


Read More

Leave a Reply