admin管理员组

文章数量:1336632

This should b really easy but I can't find reference - easy points for someone!

I have an option in my wp_options table, and need to set it via update_option(). I just can't find the correct syntax for doing something similar to the following where I update the key object_key in the option my_plugin_settings where this is an option in my wp_options table:

update_option('my_plugin_settings[object_key]','new value');

How is it done correctly?

This should b really easy but I can't find reference - easy points for someone!

I have an option in my wp_options table, and need to set it via update_option(). I just can't find the correct syntax for doing something similar to the following where I update the key object_key in the option my_plugin_settings where this is an option in my wp_options table:

update_option('my_plugin_settings[object_key]','new value');

How is it done correctly?

Share Improve this question edited Dec 8, 2013 at 2:08 Brian asked Dec 8, 2013 at 1:54 BrianBrian 8142 gold badges11 silver badges20 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

Sorry for being dense, you need to grab the object, overwrite the key you want to set and then save the updated object as the new option:

$my_plugin_settings = get_option('my_plugin_settings');
$my_plugin_settings->object_key = 'new_value';
update_option('my_plugin_settings', $my_plugin_settings);

You don't update a key, you get the entire option group as an array, then update the key you want, like normal array edit, then update the entire option group.

$option_group = get_option('group_name');

$option_group['option_to_update'] = 'new value';

update_option( 'group_name', $option_group );

本文标签: theme developmentUpdate Specific Key Value in Complex wpoptions object