Wp post meta get (WP-CLI): verschil tussen versies
Naar navigatie springen
Naar zoeken springen
Regel 72: | Regel 72: | ||
wp post meta get 7 buttonbars_${bb}_buttonbar_title | wp post meta get 7 buttonbars_${bb}_buttonbar_title | ||
wp post meta get $id buttonbars_${bb}_buttonbar_title | wp post meta get $id buttonbars_${bb}_buttonbar_title | ||
+ | </pre> | ||
+ | |||
+ | == Check for the existence of an attachment == | ||
+ | |||
+ | Use case: A script to update alt texts of images. Along the way, first check if the given post id actually corresponds to an image. | ||
+ | |||
+ | Examples: | ||
+ | |||
+ | <pre> | ||
+ | # | ||
+ | # Post-id refers to an image | ||
+ | ##################################### | ||
+ | # | ||
+ | $ wp post meta get 62808 _wp_attached_file | ||
+ | |||
+ | 2021/06/4611-0283_3-LOGO.jpg | ||
+ | |||
+ | |||
+ | # post-id doesn't exist | ||
+ | ##################################### | ||
+ | # | ||
+ | $ wp post meta get 63948 _wp_attached_file | ||
+ | |||
+ | Error: Could not find the post with ID 63948. | ||
+ | |||
+ | |||
+ | # post-id exists, but isn't an image | ||
+ | ##################################### | ||
+ | # | ||
+ | $ wp post meta get 7 _wp_attached_file | ||
+ | |||
+ | # No output | ||
</pre> | </pre> | ||
Versie van 21 sep 2023 11:50
wp post meta get: Get the values for a particular meta object. In other words: What does the value
field in table wp_postmeta
say for this id
and this key
. This works for both scalars and serialized data.
$ wp help post meta get NAME wp post meta get DESCRIPTION Get meta field value. SYNOPSIS wp post meta get <id> <key> [--format=<format>] OPTIONS <id> The ID of the object. <key> The name of the meta field to get. [--format=<format>] Get value in a particular format. --- default: var_export options: - var_export - json - yaml ---
Voorbeelden
Gebaseerd op het voorbeeld hieronder tav. wp post meta list
:
wp post meta get 7 hero_text <!-- First version - Until 2020.09.25 <h2>BlahBlah</h2> --> <!-- <h2>BlahBlah-2</h2> --> <h2>BlahBlah-3</h2>
Dit werkt ook voor serialised data:
wp post meta get 7 banner_pick_tool_link array ( 'title' => 'Onze widget-Keuzehulp >', 'url' => 'http://en.s1/widget-keuzehulp/', 'target' => '', )
Hoe je parameters kunt gebruiken in de argumenten: Alledrie de varianten werken:
id=7 bb=3 wp post meta get 7 buttonbars_3_buttonbar_title wp post meta get 7 buttonbars_${bb}_buttonbar_title wp post meta get $id buttonbars_${bb}_buttonbar_title
Check for the existence of an attachment
Use case: A script to update alt texts of images. Along the way, first check if the given post id actually corresponds to an image.
Examples:
# # Post-id refers to an image ##################################### # $ wp post meta get 62808 _wp_attached_file 2021/06/4611-0283_3-LOGO.jpg # post-id doesn't exist ##################################### # $ wp post meta get 63948 _wp_attached_file Error: Could not find the post with ID 63948. # post-id exists, but isn't an image ##################################### # $ wp post meta get 7 _wp_attached_file # No output