theme development - Update Specific Key Value in Complex `wp_options` object

This should b really easy but I can't find reference - easy points for someone!I have an option in my wp_options ta

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 );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742398565a4436443.html

相关推荐

  • theme development - Update Specific Key Value in Complex `wp_options` object

    This should b really easy but I can't find reference - easy points for someone!I have an option in my wp_options ta

    21小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信