How to update keyvalue option?

by yarek   Last Updated August 14, 2019 15:08 PM

I use this command to get values of ez-toc-settings->auto_insert_post_types

wp eval "print_r(get_option('ez-toc-settings')['auto_insert_post_types']);"

and this prints out the correct values:

    [post] => post
    [page] => page

Now, I try to modify that so I have only "post" value I tried with:

wp eval "update_option('ez-toc-settings auto_insert_post_types', array('post'));"

Infact I have no idea on how to update a key value within an option

Answers 1

wp option does all you need. See wp option patch in particular.

Updates a nested value in an option.

Get a nested option value:

$ wp option pluck ez-toc-settings auto_insert_post_types

Set a nested option value (with an array):

$ wp option patch update ez-toc-settings auto_insert_post_types '{"post": "post"}' –-format=json
August 14, 2019 13:53 PM

Related Questions

Add Option if Not Exists

Updated July 07, 2018 10:08 AM

Why isn't get_option array contents displaying?

Updated April 25, 2015 21:03 PM