Wp post (WP-CLI): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
(Nieuwe pagina aangemaakt met ''' wp post '': Manages posts, content (pages), and meta <code>wp help post</code>: <pre> NAME wp post DESCRIPTION Manages posts, content, and meta. SYNOPS...')
 
(Tekst vervangen door "'' wp post '': Manages posts, content (pages), and meta <code>wp help post</code>: <pre> NAME wp post DESCRIPTION Manages posts, content, and meta. SYNOPSIS wp...")
Label: Vervangen
Regel 44: Regel 44:
 
</pre>
 
</pre>
  
''' Bronnen '''
+
== Zie ook ==
  
* https://developer.wordpress.org/cli/commands/post/create/
+
* [[wp post create (WP-CLI) | wp post create]]
 
+
* [[wp post delete (WP-CLI) | wp post delete]]
== wp post create ==
+
* [[wp post edit (WP-CLI) | wp post edit]]
 
+
* [[wp post generate (WP-CLI) | wp post generate]]
''' Voorbeelden '''
+
* [[wp post get (WP-CLI) | wp post get]]
 
+
* [[wp post list (WP-CLI) | wp post list]]
<pre>
+
* [[wp post meta (WP-CLI) | wp post meta]]
# * Zonder post_status wordt de status "draft"
+
* [[wp post meta get (WP-CLI) | wp post meta get]]
# * Als je dit commando herhaalt, krijg je een nieuwe pagina met dezelfde titel
+
* [[wp post meta list (WP-CLI) | wp post meta list]]
#  Er wordt dus geen bestaande pagina aangepast
+
* [[wp post meta patch (WP-CLI) | wp post meta patch]]
#
+
* [[wp post meta pluck (WP-CLI) | wp post meta pluck]]
wp post create \
+
* [[wp post meta update (WP-CLI) | wp post meta update]]
              \
+
* [[wp post term (WP-CLI) | wp post term]]
  --post_type=page \
+
* [[wp post update (WP-CLI) | wp post update]]
  --post_title='test (3)' \
 
  --post_content="Jantje zag eens pruimen hangen" \
 
  --post_status="publish"
 
</pre>
 
 
 
<pre>
 
##############################################################
 
# Creeer een pagina + get id
 
##############################################################
 
#
 
i2=$( \
 
  wp post create \
 
                \
 
    --post_type=page \
 
    --post_title='test (3)' \
 
    --post_content="Jantje zag eens pruimen hangen" \
 
    --post_status="publish" \
 
| sed "s/^Success: Created post //" | sed "s/\.//" 
 
)
 
 
 
echo "Gevonden: $i2"
 
</pre>
 
  
''' Bronnen '''
+
== Bronnen ==
  
 
* https://developer.wordpress.org/cli/commands/post/create/
 
* https://developer.wordpress.org/cli/commands/post/create/
* Voor opties: https://developer.wordpress.org/reference/functions/wp_insert_post/
 
 
== wp post delete ==
 
 
* Let op: Dit commando verwijdert zowel ''posts'' als ''pages''. Dat kan soms verwarring geven.
 
* Geweldige voorbeelden: https://wordpress.stackexchange.com/questions/262823/how-can-i-batch-delete-all-unattached-images-with-wp-cli-or-other-automated-proc
 
 
<pre>
 
$ wp help post delete
 
 
NAME
 
 
  wp post delete
 
 
DESCRIPTION
 
 
  Deletes an existing post.
 
 
SYNOPSIS
 
 
  wp post delete <id>... [--force] [--defer-term-counting]
 
 
OPTIONS
 
 
  <id>...
 
    One or more IDs of posts to delete.
 
 
  [--force]
 
    Skip the trash bin.
 
 
  [--defer-term-counting]
 
    Recalculate term count in batch, for a performance boost.
 
 
EXAMPLES
 
 
    # Delete post skipping trash
 
    $ wp post delete 123 --force
 
    Success: Deleted post 123.
 
 
    # Delete all pages
 
    $ wp post delete $(wp post list --post_type='page' --format=ids)
 
    Success: Trashed post 1164.
 
    Success: Trashed post 1186.
 
 
    # Delete all posts in the trash
 
    $ wp post delete $(wp post list --post_status=trash --format=ids)
 
    Success: Deleted post 1268.
 
    Success: Deleted post 1294.
 
</pre>
 
 
'''Voorbeeld'''
 
 
<pre>
 
##############################################################
 
# Verwijder sample pagina
 
##############################################################
 
#
 
wp post list
 
wp post delete 1
 
</pre>
 
 
Output:
 
 
<pre>
 
+----+--------------+-------------+---------------------+-------------+
 
| ID | post_title  | post_name  | post_date          | post_status |
 
+----+--------------+-------------+---------------------+-------------+
 
| 1  | Hello world! | hello-world | 2017-12-02 11:37:28 | publish    |
 
+----+--------------+-------------+---------------------+-------------+
 
Success: Trashed post 1.
 
</pre>
 
 
Nog een keer, maar nu echt:
 
 
<pre>
 
##############################################################
 
# Verwijder sample pagina
 
##############################################################
 
#
 
wp post list --post_type="page"
 
wp post delete 2
 
</pre>
 
 
Output:
 
 
<pre>
 
+----+-------------+-------------+---------------------+-------------+
 
| ID | post_title  | post_name  | post_date          | post_status |
 
+----+-------------+-------------+---------------------+-------------+
 
| 2  | Sample Page | sample-page | 2017-12-02 11:37:28 | publish    |
 
+----+-------------+-------------+---------------------+-------------+
 
Success: Trashed post 2.
 
</pre>
 
 
''' Verwijder alle producten '''
 
 
Toon de ID's van alle WooCommerce-producten: <code>wp post list --post_type=product --field=ID</code>. Hier lijkt geen limiet van bv. max. 100 rijen te gelden.
 
 
== wp post edit ==
 
 
 
== wp post generate ==
 
 
Creates a specified number of new posts with dummy data.
 
 
== wp post get ==
 
 
Get details about a post.
 
 
Voorbeeld:
 
 
<pre>
 
$ wp post get 51110
 
 
+-----------------------+---------------------------------------------+
 
| Field                | Value                                      |
 
+-----------------------+---------------------------------------------+
 
| ID                    | 51110                                      |
 
| post_author          | 4                                          |
 
| post_date            | 2020-05-05 18:13:15                        |
 
| post_date_gmt        | 2020-05-05 18:13:15                        |
 
| post_content          |                                            |
 
| post_title            | Widgets for ABC - Kies je Toepassing        |
 
| post_excerpt          |                                            |
 
| post_status          | publish                                    |
 
| comment_status        | closed                                      |
 
| ping_status          | closed                                      |
 
| post_password        |                                            |
 
| post_name            | widgets-voor-abc-kies-je-apparaat          |
 
| to_ping              |                                            |
 
| pinged                |                                            |
 
| post_modified        | 2021-03-12 13:17:54                        |
 
| post_modified_gmt    | 2021-03-12 12:17:54                        |
 
| post_content_filtered |                                            |
 
| post_parent          | 0                                          |
 
| guid                  | http://en.s1/?page_id=51110                |
 
| menu_order            | 0                                          |
 
| post_type            | page                                        |
 
| post_mime_type        |                                            |
 
| comment_count        | 0                                          |
 
| nl                    | null                                        |
 
+-----------------------+---------------------------------------------+
 
</pre>
 
 
== wp post list ==
 
 
Retrieve a list of posts/pages/etc.
 
 
* Without additional specifications, this command is limited to ''posts'' only - Pages, products, etc. will be excluded. Do note however, that ''ID'' is global. So this problem doesn't occur when editing stuff
 
* Option <code>--posts_per_page</code> is supported, but not much documented
 
* Option <code>--offset</code> is supported, but not much documented.
 
 
<pre>
 
$ wp help post list
 
 
NAME
 
 
  wp post list
 
 
DESCRIPTION
 
 
  Gets a list of posts.
 
 
SYNOPSIS
 
 
  wp post list [--<field>=<value>] [--field=<field>] [--fields=<fields>] [--format=<format>]
 
 
  Display posts based on all arguments supported by
 
  [WP_Query()][1].
 
 
  ---
 
  [1] https://developer.wordpress.org/reference/classes/wp_query/
 
 
OPTIONS
 
 
  [--<field>=<value>]
 
    One or more args to pass to WP_Query.
 
 
  [--field=<field>]
 
    Prints the value of a single field for each post.
 
 
  [--fields=<fields>]
 
    Limit the output to specific object fields.
 
 
  [--format=<format>]
 
    Render output in a particular format.
 
    ---
 
    default: table
 
    options:
 
      - table
 
      - csv
 
      - ids
 
      - json
 
      - count
 
      - yaml
 
    ---
 
 
AVAILABLE FIELDS
 
 
  These fields will be displayed by default for each post:
 
 
  * ID
 
  * post_title
 
  * post_name
 
  * post_date
 
  * post_status
 
 
  These fields are optionally available:
 
 
  * post_author
 
  * post_date_gmt
 
  * post_content
 
  * post_excerpt
 
  * comment_status
 
  * ping_status
 
  * post_password
 
  * to_ping
 
  * pinged
 
  * post_modified
 
  * post_modified_gmt
 
  * post_content_filtered
 
  * post_parent
 
  * guid
 
  * menu_order
 
  * post_type
 
  * post_mime_type
 
  * comment_count
 
  * filter
 
  * url
 
 
EXAMPLES
 
 
    # List post
 
    $ wp post list --field=ID
 
    568
 
    829
 
    1329
 
    1695
 
 
    # List posts in JSON
 
    $ wp post list --post_type=post --posts_per_page=5 --format=json
 
    [{"ID":1,"post_title":"Hello world!","post_name":"hello-world","post_date":"2015-06-20
 
    09:00:10","post_status":"publish"},{"ID":1178,"post_title":"Markup: HTML Tags and
 
    Formatting","post_name":"markup-html-tags-and-formatting","post_date":"2013-01-11
 
    20:22:19","post_status":"draft"}]
 
 
    # List all pages
 
    $ wp post list --post_type=page --fields=post_title,post_status
 
    +-------------+-------------+
 
    | post_title  | post_status |
 
    +-------------+-------------+
 
    | Sample Page | publish    |
 
    +-------------+-------------+
 
 
    # List ids of all pages and posts
 
    $ wp post list --post_type=page,post --format=ids
 
    15 25 34 37 198
 
 
    # List given posts
 
    $ wp post list --post__in=1,3
 
    +----+--------------+-------------+---------------------+-------------+
 
    | ID | post_title  | post_name  | post_date          | post_status |
 
    +----+--------------+-------------+---------------------+-------------+
 
    | 3  | Lorem Ipsum  | lorem-ipsum | 2016-06-01 14:34:36 | publish    |
 
    | 1  | Hello world! | hello-world | 2016-06-01 14:31:12 | publish    |
 
    +----+--------------+-------------+---------------------+-------------+
 
</pre>
 
 
''' Voorbeelden '''
 
 
<pre>
 
wp post list # This lists "posts" only
 
 
+----+--------------+-------------+---------------------+-------------+
 
| ID | post_title  | post_name  | post_date          | post_status |
 
+----+--------------+-------------+---------------------+-------------+
 
| 1  | Hello world! | hello-world | 2017-11-26 11:11:28 | publish    |
 
+----+--------------+-------------+---------------------+-------------+
 
</pre>
 
 
<pre>
 
wp post list --post_type=page
 
 
+----+---------------+---------------+---------------------+-------------+
 
| ID | post_title    | post_name    | post_date          | post_status |
 
+----+---------------+---------------+---------------------+-------------+
 
| 7  | test (3)      |              | 2017-11-26 12:26:42 | draft      |
 
| 6  | test (2)      | test-2        | 2017-11-26 12:23:05 | publish    |
 
| 2  | Sample Page  | sample-page  | 2017-11-26 11:11:28 | publish    |
 
+----+---------------+---------------+---------------------+-------------+
 
</pre>
 
 
<pre>
 
# Show products
 
#
 
wp post list --post_type=product
 
</pre>
 
 
<pre>
 
# Je kunt filteren op post_name, maar niet op post_title
 
#
 
wp post list --post_type=page --name="test-3" --field=ID
 
 
8
 
</pre>
 
 
<pre>
 
# Redirect output naar een variable: Gebruik i=$(...)
 
#
 
i=$(wp post list --post_type=page --name="test-3" --field=ID)
 
echo "gevonden id: $i"
 
</pre>
 
 
<pre>
 
# When selecting multiple fields, there is no space after the comma
 
#
 
wp post list --post_type="page" --fields=ID,post_title,post_name
 
 
+-------+---------------------------------------------------------------------------+--------------------------------------------------------------------+
 
| ID    | post_title                                                                | post_name                                                          |
 
+-------+---------------------------------------------------------------------------+--------------------------------------------------------------------+
 
| 63472 | Widgets met kortste afmeting groter dan 10 mm                            | Widgets-met-kortste-afmeting-groter-dan10-mm                      |
 
| 63469 | Widgets met kortste afmeting 10mm                                        | Widgets-met-kortste-afmeting-10mm                                  |
 
| 63467 | Widgets met kortste afmeting tussen 8 & 10 mm                            | Widgets-met-kortste-afmeting-tussen-8-10-mm                        |
 
| 63252 | Alle afmetingen                                                          |                                                                    |
 
| 63239 | Widgets met kortste afmeting tot 5mm                                      | Widgets-met-kortste-afmeting-tot-5mm                              |
 
| 63233 | Widgets 5x8mm - Zonder stroomdraad, zonder connector - With spring        | Widgets-5x8mm-zonder-stroomdraad-zonder-connector-met-veer        |
 
| 51513 | Zoeken op afbeelding - Diagram 93                                        | zoeken-op-afbeelding-diagram-93                                    |
 
| 51507 | Zoeken op afbeelding - Diagram 79                                        | zoeken-op-afbeelding-diagram-79                                    |
 
| 51167 | Widgets for Vritex - Kies je Toepassing                                  | Widgets-voor-vritex-kies-je-apparaat                              |
 
| 51165 | Widgets for Styr - Kies je Toepassing                                    | Widgets-voor-styr-kies-je-apparaat                                |
 
| 51163 | Widgets for Spt - Kies je Toepassing                                      | Widgets-voor-spt-kies-je-apparaat                                  |
 
| 413  | Shop                                                                      | shop                                                              |
 
| 393  | Zoeken op Afbeelding                                                      | zoeken-op-afbeelding                                              |
 
| 181  | Over ons                                                                  | over-ons                                                          |
 
| 101  | Contact                                                                  | contact                                                            |
 
| 11    | Winkelmand                                                                | winkelmand                                                        |
 
| 12    | Checkout                                                                  | checkout                                                          |
 
| 13    | Mijn account                                                              | mijn-account                                                      |
 
| 7    | Webshop for Widgets                                                      | webshop-widgets                                                    |
 
+-------+---------------------------------------------------------------------------+--------------------------------------------------------------------+
 
</pre>
 
<pre>
 
# Use of "--posts_per_page" & "--offset":
 
#
 
wp post list --post_type="page" --posts_per_page=5 --offset=12;
 
</pre>
 
 
== wp post meta ==
 
 
<pre>
 
$ wp help post meta
 
 
NAME
 
 
  wp post meta
 
 
DESCRIPTION
 
 
  Adds, updates, deletes, and lists post custom fields.
 
 
SYNOPSIS
 
 
  wp post meta <command>
 
 
SUBCOMMANDS
 
 
  add        Add a meta field.
 
  delete      Delete a meta field.
 
  get        Get meta field value.
 
  list        List all metadata associated with an object.
 
  patch      Update a nested value for a meta field.
 
  pluck      Get a nested value from a meta field.
 
  update      Update a meta field.
 
 
EXAMPLES
 
 
    # Set post meta
 
    $ wp post meta set 123 _wp_page_template about.php
 
    Success: Updated custom field '_wp_page_template'.
 
 
    # Get post meta
 
    $ wp post meta get 123 _wp_page_template
 
    about.php
 
 
    # Update post meta
 
    $ wp post meta update 123 _wp_page_template contact.php
 
    Success: Updated custom field '_wp_page_template'.
 
 
    # Delete post meta
 
    $ wp post meta delete 123 _wp_page_template
 
    Success: Deleted custom field.
 
</pre>
 
 
== wp post meta get ==
 
 
Verkrijg de waardes voor een bepaald meta-object. Oftewel: Wat staat er in het <code>value</code>-veld in tabel <code>wp_postmeta</code> voor dit <code>id</code> en deze <code>key</code>. Dit werkt voor zowel scalars als serialised data.
 
 
<pre>
 
# 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
 
    ---
 
</pre>
 
 
''' Voorbeelden '''
 
 
Gebaseerd op het voorbeeld hieronder tav. <code>wp post meta list</code>:
 
 
<pre>
 
wp post meta get 7 hero_text
 
 
<!--
 
First version - Until 2020.09.25
 
<h2>BlahBlah</h2>
 
-->
 
<!--
 
<h2>BlahBlah-2</h2>
 
-->
 
<h2>BlahBlah-3</h2>
 
</pre>
 
 
Dit werkt ook voor serialised data:
 
 
<pre>
 
wp post meta get 7 banner_pick_tool_link
 
 
array (
 
  'title' => 'Onze widget-Keuzehulp >',
 
  'url' => 'http://en.s1/widget-keuzehulp/',
 
  'target' => '',
 
)
 
</pre>
 
 
Hoe je parameters kunt gebruiken in de argumenten: Alledrie de varianten werken:
 
 
<pre>
 
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
 
</pre>
 
 
== wp post meta list ==
 
 
Verkrijg een lijst met alle meta-velden van een post:
 
 
* Wil je in detail zien wat er in een specifiek metaveld zit? Gebruik dan <code>wp post meta get</code>
 
* Het lijkt niet mogelijk te zijn om ''alle'' waardes van een bepaald meta-veld te zien, ongeacht het ID. Daar kan in SQL weer heel gemakkelijk, bv.: <code>sql_string='select * from wp_termmeta where meta_key = "product_category_text";'; wp db query "$sql_string"</code>
 
 
 
<pre>
 
$ wp help post meta list
 
 
NAME
 
 
  wp post meta list
 
 
DESCRIPTION
 
 
  List all metadata associated with an object.
 
 
SYNOPSIS
 
 
  wp post meta list <id> [--keys=<keys>] [--fields=<fields>] [--format=<format>] [--orderby=<fields>]
 
  [--order=<order>] [--unserialize]
 
 
OPTIONS
 
 
  <id>
 
    ID for the object.
 
 
  [--keys=<keys>]
 
    Limit output to metadata of specific keys.
 
 
  [--fields=<fields>]
 
    Limit the output to specific row fields. Defaults to id,meta_key,meta_value.
 
 
  [--format=<format>]
 
    Render output in a particular format.
 
    ---
 
    default: table
 
    options:
 
      - table
 
      - csv
 
      - json
 
      - yaml
 
      - count
 
    ---
 
 
  [--orderby=<fields>]
 
    Set orderby which field.
 
    ---
 
    default: id
 
    options:
 
    - id
 
    - meta_key
 
    - meta_value
 
    ---
 
 
  [--order=<order>]
 
    Set ascending or descending order.
 
    ---
 
    default: asc
 
    options:
 
    - asc
 
    - desc
 
    ---
 
 
[--unserialize]
 
    Unserialize meta_value output.
 
</pre>
 
'''Voorbeeld (1)'''
 
 
Handjevol velden van een home page met 1.308 meta-objecten (hoe ik dat weet? <code>wp post meta list 7 | wc -l</code>):
 
 
<pre>
 
wp post meta list 7
 
 
+---------+----------------------------------------------------+-----------------------------------------------------+
 
| post_id | meta_key                                          | meta_value                                          |
 
+---------+----------------------------------------------------+-----------------------------------------------------+
 
| 7      | _edit_last                                        | 9                                                  |
 
| 7      | _wp_page_template                                  | templates/page-home2021.php                        |
 
| 7      | _edit_lock                                        | 1627579027:4                                        |
 
| 7      | hero_background                                    | 55538                                              |
 
| 7      | _hero_background                                  | field_5d4d3c8072ecc                                |
 
| 7      | hero_text                                          | <!-- First version - Until 2020.09.25 <h2>blah</h2> |                                |
 
| 7      | _hero_text                                        | field_5d4d3c8f72ecd                                |
 
| 7      | hero_ctas_0_link                                  | a:3:{s:5:"title";s:24:"Bekijk alle widgets";s:      |
 
+---------+----------------------------------------------------+-----------------------------------------------------+
 
</pre>
 
 
'''Voorbeeld (2)'''
 
 
Alleen de velden ''meta_key'' en ''meta_value'' en alleen als ergens het woord ''shop'' voorkomt. En schrijf dit naar een bestand (als het om veel informatie gaat, vind ik tekstbestanden een stuk handiger dan de output in een terminal):
 
 
<pre>
 
wp post meta list 51114 --fields=meta_key,meta_value | grep shop > tmp.txt
 
</pre>
 
 
''' Voorbeeld (3): --keys'''
 
 
Met <code>--keys</code> beperk je output tot geselecteerde meta-keys:
 
 
<pre>
 
$ wp post meta list 7 --keys=buttonbars_3_buttonbar_selection_10_title
 
 
+---------+-------------------------------------------+-----------------+
 
| post_id | meta_key                                  | meta_value      |
 
+---------+-------------------------------------------+-----------------+
 
| 7      | buttonbars_3_buttonbar_selection_10_title | Groter dan 10mm |
 
+---------+-------------------------------------------+-----------------+
 
</pre>
 
 
== wp post meta patch ==
 
 
Gebruik <code>wp post meta patch</code> om een serialised veld bij te werken.
 
 
<pre>
 
$ wp help post meta patch
 
 
NAME
 
 
  wp post meta patch
 
 
DESCRIPTION
 
 
  Update a nested value for a meta field.
 
 
SYNOPSIS
 
 
  wp post meta patch <action> <id> <key> <key-path>... [<value>] [--format=<format>]
 
 
OPTIONS
 
 
  <action>
 
    Patch action to perform.
 
    ---
 
    options:
 
      - insert
 
      - update
 
      - delete
 
    ---
 
 
  <id>
 
    The ID of the object.
 
 
  <key>
 
    The name of the meta field to update.
 
 
  <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
 
    ---
 
</pre>
 
 
Voorbeeld:
 
 
<pre>
 
$ wp post meta get 7 banner_pick_tool_link
 
 
array (
 
  'title' => 'Onze widget-Keuzehulp >',
 
  'url' => 'http://en.s1/widget-keuzehulp/',
 
  'target' => '',
 
)
 
 
 
$ wp post meta pluck 7 banner_pick_tool_link "title"
 
 
Onze widget-Keuzehulp >
 
 
 
$ wp post meta patch update 7 banner_pick_tool_link "title" "Our Widget Selection Tool >"
 
 
Success: Updated custom field 'banner_pick_tool_link'.
 
</pre>
 
 
== wp post meta pluck ==
 
 
Gebruik <code>wp post meta pluck</code> om een serialised veld uit te lezen.
 
 
Voorbeeld:
 
 
<pre>
 
$ wp post meta get 7 banner_pick_tool_link
 
 
array (
 
  'title' => 'Onze widget-Keuzehulp >',
 
  'url' => 'http://en.s1/widget-keuzehulp/',
 
  'target' => '',
 
)
 
 
 
$ wp post meta pluck 7 banner_pick_tool_link "title"
 
 
Onze widget-Keuzehulp >
 
</pre>
 
 
== wp post meta update ==
 
 
Bewerkt een bestaand enkelvoudig (non-serialised) meta-veld:
 
 
* <code>id</code>: ID van de pagina, post of object
 
* <code>key</code>: Naam van het veld of object op de betreffende pagina.
 
 
<pre>
 
$ wp help post meta update
 
 
NAME
 
 
  wp post meta update
 
 
DESCRIPTION
 
 
  Update a meta field.
 
 
SYNOPSIS
 
 
  wp post meta update <id> <key> [<value>] [--format=<format>]
 
 
ALIAS
 
 
  set
 
 
OPTIONS
 
 
  <id>
 
    The ID of the object.
 
 
  <key>
 
    The name of the meta field to update.
 
 
  [<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
 
    ---
 
</pre>
 
 
== wp post term ==
 
 
 
== wp post update ==
 
 
<pre>
 
$ wp help wp post update
 
 
NAME
 
 
  wp post update
 
 
DESCRIPTION
 
 
  Updates one or more existing posts.
 
 
SYNOPSIS
 
 
  wp post update <id>... [--post_author=<post_author>] [--post_date=<post_date>] [--post_date_gmt=<post_date_gmt>] [--post_content=<post_content>] [--post_content_filtered=<post_content_filtered>] [--post_title=<post_title>]
 
  [--post_excerpt=<post_excerpt>] [--post_status=<post_status>] [--post_type=<post_type>] [--comment_status=<comment_status>] [--ping_status=<ping_status>] [--post_password=<post_password>] [--post_name=<post_name>] [--to_ping=<to_ping>]
 
  [--pinged=<pinged>] [--post_modified=<post_modified>] [--post_modified_gmt=<post_modified_gmt>] [--post_parent=<post_parent>] [--menu_order=<menu_order>] [--post_mime_type=<post_mime_type>] [--guid=<guid>]
 
  [--post_category=<post_category>] [--tags_input=<tags_input>] [--tax_input=<tax_input>] [--meta_input=<meta_input>] [<file>] --<field>=<value> [--defer-term-counting]
 
 
OPTIONS
 
 
  <id>...
 
    One or more IDs of posts to update.
 
 
  [--post_author=<post_author>]
 
    The ID of the user who added the post. Default is the current user ID.
 
 
  [--post_date=<post_date>]
 
    The date of the post. Default is the current time.
 
 
  [--post_date_gmt=<post_date_gmt>]
 
    The date of the post in the GMT timezone. Default is the value of $post_date.
 
 
  [--post_content=<post_content>]
 
    The post content. Default empty.
 
 
  [--post_content_filtered=<post_content_filtered>]
 
    The filtered post content. Default empty.
 
 
  [--post_title=<post_title>]
 
    The post title. Default empty.
 
 
  [--post_excerpt=<post_excerpt>]
 
    The post excerpt. Default empty.
 
 
  [--post_status=<post_status>]
 
    The post status. Default 'draft'.
 
 
  [--post_type=<post_type>]
 
    The post type. Default 'post'.
 
 
  [--comment_status=<comment_status>]
 
    Whether the post can accept comments. Accepts 'open' or 'closed'. Default is the value of 'default_comment_status' option.
 
 
  [--ping_status=<ping_status>]
 
    Whether the post can accept pings. Accepts 'open' or 'closed'. Default is the value of 'default_ping_status' option.
 
 
  [--post_password=<post_password>]
 
    The password to access the post. Default empty.
 
 
[--post_name=<post_name>]
 
    The post name. Default is the sanitized post title when creating a new post.
 
 
  [--to_ping=<to_ping>]
 
    Space or carriage return-separated list of URLs to ping. Default empty.
 
 
  [--pinged=<pinged>]
 
    Space or carriage return-separated list of URLs that have been pinged. Default empty.
 
 
  [--post_modified=<post_modified>]
 
    The date when the post was last modified. Default is the current time.
 
 
  [--post_modified_gmt=<post_modified_gmt>]
 
    The date when the post was last modified in the GMT timezone. Default is the current time.
 
 
  [--post_parent=<post_parent>]
 
    Set this for the post it belongs to, if any. Default 0.
 
 
  [--menu_order=<menu_order>]
 
    The order the post should be displayed in. Default 0.
 
 
  [--post_mime_type=<post_mime_type>]
 
    The mime type of the post. Default empty.
 
 
  [--guid=<guid>]
 
    Global Unique ID for referencing the post. Default empty.
 
 
  [--post_category=<post_category>]
 
    Array of category names, slugs, or IDs. Defaults to value of the 'default_category' option.
 
 
  [--tags_input=<tags_input>]
 
    Array of tag names, slugs, or IDs. Default empty.
 
 
  [--tax_input=<tax_input>]
 
    Array of taxonomy terms keyed by their taxonomy name. Default empty.
 
 
  [--meta_input=<meta_input>]
 
    Array in JSON format of post meta values keyed by their post meta key. Default empty.
 
 
  [<file>]
 
    Read post content from <file>. If this value is present, the
 
        `--post_content` argument will be ignored.
 
 
  Passing `-` as the filename will cause post content to
 
  be read from STDIN.
 
 
  --<field>=<value>
 
    One or more fields to update. See wp_insert_post().
 
 
  [--defer-term-counting]
 
    Recalculate term count in batch, for a performance boost.
 
 
EXAMPLES
 
 
    $ wp post update 123 --post_name=something --post_status=draft
 
    Success: Updated post 123.
 
 
    # Update a post with multiple meta values.
 
    $ wp post update 123 --meta_input='{"key1":"value1","key2":"value2"}'
 
    Success: Updated post 123.
 
</pre>
 
 
'''Voorbeelden'''
 
 
[https://developer.wordpress.org/cli/commands/post/update/]:
 
 
<pre>
 
# post_name = slug <> post_title
 
########################################
 
#
 
wp post update 123 --post_name=something --post_status=draft
 
Success: Updated post 123.
 
 
# Update a post with multiple meta values.
 
########################################
 
#
 
wp post update 123 --meta_input='{"key1":"value1","key2":"value2"}'
 
Success: Updated post 123.
 
</pre>
 
 
Eigen voorbeeld:
 
 
<pre>
 
# Titel & name bijwerken:
 
########################################
 
#
 
wp post update 7 --post_name="webshop-widgets"
 
wp post update 7 --post_title="Webshop for Widgets"
 
</pre>
 

Versie van 17 jun 2022 15:44

wp post : Manages posts, content (pages), and meta

wp help post:

NAME

  wp post

DESCRIPTION

  Manages posts, content, and meta.

SYNOPSIS

  wp post <command>

SUBCOMMANDS

  create        Creates a new post.
  delete        Deletes an existing post.
  edit          Launches system editor to edit post content.
  exists        Verifies whether a post exists.
  generate      Generates some posts.
  get           Gets details about a post.
  list          Gets a list of posts.
  meta          Adds, updates, deletes, and lists post custom fields.
  term          Adds, updates, removes, and lists post terms.
  update        Updates one or more existing posts.

EXAMPLES

    # Create a new post.
    $ wp post create --post_type=post --post_title='A sample post'
    Success: Created post 123.

    # Update an existing post.
    $ wp post update 123 --post_status=draft
    Success: Updated post 123.

    # Delete an existing post.
    $ wp post delete 123
    Success: Trashed post 123.

Zie ook

Bronnen