Wp option pluck (WP-CLI): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
Regel 289: Regel 289:
 
* [[wp option update (WP-CLI) |                    wp option update]]
 
* [[wp option update (WP-CLI) |                    wp option update]]
  
== Bronnen ==
+
== Sources ==
  
 
* https://github.com/wp-cli/entity-command/issues/106
 
* https://github.com/wp-cli/entity-command/issues/106
 
* https://guides.wp-bullet.com/using-wp-cli-to-batch-update-serialized-wp_options-settings/
 
* https://guides.wp-bullet.com/using-wp-cli-to-batch-update-serialized-wp_options-settings/

Versie van 29 aug 2022 08:53

Get a serialized value:

  • You can request a subtree/subfield with this - This cannot be done with wp option get
  • Specify the path of elements (space-separated) to get to the appropriate subtree or subfield.
$ wp help option pluck

NAME

  wp option pluck

DESCRIPTION

  Gets a nested value from an option.

SYNOPSIS

  wp option pluck <key> <key-path>... [--format=<format>]

OPTIONS

  <key>
    The option name.

  <key-path>...
    The name(s) of the keys within the value to locate the value to pluck.

  [--format=<format>]
    The output format of the value.
    ---
    default: plaintext
    options:
      - plaintext
      - json
      - yaml
    ---

Simple example

wp option get options_footer_links_1_0_link

array (
  'title' => 'Widget GLX',
  'url' => 'http://en.s1/shop/glx/',
  'target' => '',
)


wp option pluck options_footer_links_1_0_link title

Widget GLX

Example nested tree

Now it gets more fun: A serialized field with a subtree:

# Display whole serial field
########################################
#
# With "wp option get", you cannot select a part of the tree, only the whole tree
#
wp option get aws_pro_settings

array (
  1 => 
  array (
    'search_instance' => 'Search Form',
    'filter_num' => '1',
    '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',
    'show_addon' => 'false',
    'disable_smooth' => 'false',
    'buttons_order' => '2',
    'filters' => 
    array (
      1 => 
      array (
        'filter_name' => 'All',
        'style' => 'style-inline',
        'mark_words' => 'true',
        'excerpt_length' => '20',
        'results_num' => '10',
        'outofstock' => 'true',
        'var_rules' => 'parent',
        'on_sale' => 'true',
        'product_visibility' => 
        array (
          'visible' => '1',
          'catalog' => '1',
          'search' => '1',
          'hidden' => '0',
        ),
        'search_in' => 
        array (
          'title' => 0,
          'content' => 1,
          'sku' => 1,
          'excerpt' => 0,
          'category' => '0',
          'tag' => '0',
          'id' => '0',
          'attr' => 0,
          'tax' => 0,
          'meta' => 1,
        ),
        'search_archives' => 
        array (
          'archive_category' => '0',
          'archive_tag' => '0',
          'archive_tax' => '0',
          'archive_attr' => '0',
          'archive_users' => '0',
        ),
        'highlight' => 'true',
        'show_image' => 'true',
        'show_excerpt' => 'false',
        'show_result_cats' => 'false',
        'show_result_brands' => '',
        'show_rating' => 'false',
        'show_featured' => 'false',
        'show_variations' => 'false',
        'show_price' => 'true',
        'show_outofstock_price' => 'true',
        'show_sale' => 'true',
        'show_sku' => 'false',
        'show_cart' => 'false',
        'show_stock' => 'false',
        'exclude_rel' => 'exclude',
        'adv_filters' => '',
        'search_in_attr' => 
        array (
          'attr_pa_breedte' => 0,
        ),
        'search_in_meta' => 
        array (
          'meta_post_tools' => 1,
          'meta_sku_oem' => 1,
        ),
        'product_stock_status' => 
        array (
          'in_stock' => 1,
          'out_of_stock' => 1,
          'on_backorder' => 1,
        ),
      ),
    ),
    'cache' => 'true',
    'search_logic' => 'and',
    'search_exact' => 'false',
    'desc_source' => 'content',
    'target_blank' => 'false',
    'image_source' => 'featured,gallery,content,description,default',
    'default_img' => '',
    'use_analytics' => 'false',
  ),
)

# Select part of the tree
########################################
#
wp option pluck aws_pro_settings 1

array (
  'search_instance' => 'Search Form',
  'filter_num' => '1',
  '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',
  'show_addon' => 'false',
  'disable_smooth' => 'false',
  'buttons_order' => '2',
  'filters' => 
  array (
    1 => 
    array (
      'filter_name' => 'All',
      'style' => 'style-inline',
      'mark_words' => 'true',
      'excerpt_length' => '20',
      'results_num' => '10',
      'outofstock' => 'true',
      'var_rules' => 'parent',
      'on_sale' => 'true',
      'product_visibility' => 
      array (
        'visible' => '1',
        'catalog' => '1',
        'search' => '1',
        'hidden' => '0',
      ),
      'search_in' => 
      array (
        'title' => 0,
        'content' => 1,
        'sku' => 1,
        'excerpt' => 0,
        'category' => '0',
        'tag' => '0',
        'id' => '0',
        'attr' => 0,
        'tax' => 0,
        'meta' => 1,
      ),
      'search_archives' => 
      array (
        'archive_category' => '0',
        'archive_tag' => '0',
        'archive_tax' => '0',
        'archive_attr' => '0',
        'archive_users' => '0',
      ),
      'highlight' => 'true',
      'show_image' => 'true',
      'show_excerpt' => 'false',
      'show_result_cats' => 'false',
      'show_result_brands' => '',
      'show_rating' => 'false',
      'show_featured' => 'false',
      'show_variations' => 'false',
      'show_price' => 'true',
      'show_outofstock_price' => 'true',
      'show_sale' => 'true',
      'show_sku' => 'false',
      'show_cart' => 'false',
      'show_stock' => 'false',
      'exclude_rel' => 'exclude',
      'adv_filters' => '',
      'search_in_attr' => 
      array (
        'attr_pa_breedte' => 0,
      ),
      'search_in_meta' => 
      array (
        'meta_post_tools' => 1,
        'meta_sku_oem' => 1,
      ),
      'product_stock_status' => 
      array (
        'in_stock' => 1,
        'out_of_stock' => 1,
        'on_backorder' => 1,
      ),
    ),
  ),
  'cache' => 'true',
  'search_logic' => 'and',
  'search_exact' => 'false',
  'desc_source' => 'content',
  'target_blank' => 'false',
  'image_source' => 'featured,gallery,content,description,default',
  'default_img' => '',
  'use_analytics' => 'false',
)

# Zoom in on just 1 value...
########################################
#
wp option pluck aws_pro_settings 1 search_instance

Search Form

See also

Sources