Wp option patch update (WP-CLI)
Versie door Jeroen Strompf (overleg | bijdragen) op 29 aug 2022 om 09:09
Update a serialized field:
- You indicate subfields by naming all intermediate elements (space-separated)
- NOTE: The current serialized field/subtree is overwritten by this command. For example, if you forget to mention intermediate elements, you delete the complete data model around that field
- Possibly a safe way to apply this command: First read out the current value with
wp option pluck
and only then update it with this command. - Numeric values may be with or without single/double quotes
$ wp help option patch update NAME wp option patch DESCRIPTION Updates a nested value in an option. SYNOPSIS wp option patch <action> <key> <key-path>... [<value>] [--format=<format>] OPTIONS <action> Patch action to perform. --- options: - insert - update - delete --- <key> The option name. <key-path>... The name(s) of the keys within the value to locate the value to patch. [<value>] The new value. If omitted, the value is read from STDIN. [--format=<format>] The serialization format for the value. --- default: plaintext options: - plaintext - json ---
Example (1)
$ wp option get aws_settings array ( 'seamless' => 'true', 'cache' => 'true', 'autoupdates' => 'true', 'search_in' => array ( 'title' => 1, 'content' => 0, 'sku' => 1, 'excerpt' => 0, 'category' => 0, 'tag' => 0, 'id' => 0, ), 'outofstock' => 'true', 'stopwords' => 'a, also, am, an, and, are, as, at, be, but, by, call, can, co, con, de, do, due, eg, eight, etc, even, ever, every, for, from, full, go, had, has, hasnt, have, he, hence, her, here, his, how, ie, if, in, inc, into, is, it, its, ltd, me, my, no, none, nor, not, now, of, off, on, once, one, only, onto, or, our, ours, out, over, own, part, per, put, re, see, so, some, ten, than, that, the, their, there, these, they, this, three, thru, thus, to, too, top, un, up, us, very, via, was, we, well, were, what, when, where, who, why, will', 'synonyms' => 'buy, pay, purchase, acquire box, housing, unit, package', 'use_analytics' => 'true', 'search_field_text' => 'Zoek producten...', 'show_more_text' => 'Laat alle resultaten zien', 'not_found_text' => 'Oeps, geen zoekresultaten.', 'min_chars' => '1', 'show_loader' => 'true', 'show_clear' => 'true', 'show_more' => 'true', 'mobile_overlay' => 'false', 'show_page' => 'true', 'buttons_order' => '2', 'desc_source' => 'excerpt', 'mark_words' => 'true', 'excerpt_length' => '20', 'results_num' => '10', 'highlight' => 'true', 'show_image' => 'true', 'show_excerpt' => 'false', 'show_price' => 'true', 'show_outofstock_price' => 'true', 'show_cats' => 'false', 'show_tags' => 'false', 'show_sale' => 'true', 'show_sku' => 'false', 'show_stock' => 'false', 'show_featured' => 'false', 'search_archives' => array ( 'archive_category' => 0, 'archive_tag' => 0, ), ) $ wp option pluck aws_settings search_field_text Zoek producten... $ wp option patch update aws_settings search_field_text "Search products" Success: Updated 'aws_settings' option.
Example: Numeric values & quotation marks
$ wp option pluck woocommerce_dhlpwc_settings price_option_home 6.95 $ wp option patch update woocommerce_dhlpwc_settings price_option_home "79.95" # Met dubbele aanhalingstekens Success: Updated 'woocommerce_dhlpwc_settings' option. $ wp option pluck woocommerce_dhlpwc_settings price_option_home 79.95 $ wp option patch update woocommerce_dhlpwc_settings price_option_home "79.95" # Zonder aanhalingstekens Success: Value passed for 'woocommerce_dhlpwc_settings' option is unchanged.