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 badges2 Answers
Reset to default 1Sorry 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
版权声明:本文标题:theme development - Update Specific Key Value in Complex `wp_options` object 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742398565a2467419.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论