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

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
(Nieuwe pagina aangemaakt met '== Zie ook == * wp option * wp option add * wp option del...')
 
Regel 1: Regel 1:
 +
Vraag een serialised waarde op:
 +
 +
* Je kunt hiermee een deelboom/subveld opvragen - Dit kan niet met <code>wp option get</code>
 +
* Geef het pad van elementen op (spatie-gescheiden) om bij de betreffende subboom of het subveld te komen.
 +
 +
<pre>
 +
$ 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
 +
    ---
 +
</pre>
 +
 +
'''Simpel voorbeeld'''
 +
 +
<pre>
 +
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
 +
</pre>
 +
 +
'''Voorbeeld nested tree'''
 +
 +
Nu wordt het leuker: Een serialised veld met een subboom:
 +
 +
<pre>
 +
# 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
 +
</pre>
 +
 +
'''Bronnen'''
 +
 +
* https://github.com/wp-cli/entity-command/issues/106
 +
* https://guides.wp-bullet.com/using-wp-cli-to-batch-update-serialized-wp_options-settings/
 +
 
== Zie ook ==
 
== Zie ook ==
  

Versie van 29 jul 2022 08:20

Vraag een serialised waarde op:

  • Je kunt hiermee een deelboom/subveld opvragen - Dit kan niet met wp option get
  • Geef het pad van elementen op (spatie-gescheiden) om bij de betreffende subboom of het subveld te komen.
$ 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
    ---

Simpel voorbeeld

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

Voorbeeld nested tree

Nu wordt het leuker: Een serialised veld met een subboom:

# 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

Bronnen

Zie ook