最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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 );
发布评论

评论列表(0)

  1. 暂无评论