wp post

Manages posts, content, and meta.

Commands Description
wp post create Creates a new post.
wp post update Updates one or more existing posts.
wp post edit Launches system editor to edit post content.
wp post get Gets details about a post.
wp post delete Deletes an existing post.
wp post list Gets a list of posts.
wp post generate Generates some posts.
wp post exists Verifies whether a post exists.
wp post meta list List all metadata associated with an object.
wp post meta get Get meta field value.
wp post meta delete Delete a meta field.
wp post meta add Add a meta field.
wp post meta update Update a meta field.
wp post meta pluck Get a nested value from a meta field.
wp post meta patch Update a nested value for a meta field.
wp post term list List all terms associated with an object.
wp post term remove Remove a term from an object.
wp post term add Add a term to an object.
wp post term set Set object terms.

Posts

# 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.

Posts metadata

# 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.

Posts terms

# Set post terms
$ wp post term set 123 test category
Success: Set terms.

Source code of the commands


wp post create

Creates a new post.

Usage

wp post create [--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}] [--from-post={post_id}] [--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}] [--edit] [--porcelain]

You can specify global options and the following:

[--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.
[--from-post={post_id}]
Post id of a post to be duplicated.
[--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 . 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}]
Associative args for the new post. See wp_insert_post().
[--edit]
Immediately open system's editor to write or edit post content.

If content is read from a file, from STDIN, or from the --post_content argument, that text will be loaded into the editor.

[--porcelain]
Output just the new post id.

Examples

# Create post and schedule for future
$ wp post create --post_type=page --post_title='A future post' --post_status=future --post_date='2020-12-01 07:00:00'
Success: Created post 1921.
# Create post with content from given file
$ wp post create ./post-content.txt --post_category=201,345 --post_title='Post from file'
Success: Created post 1922.
# Create a post with multiple meta values.
$ wp post create --post_title='A post' --post_content='Just a small post.' --meta_input='{"key1":"value1","key2":"value2"}'
Success: Created post 1923.
# Create a duplicate post from existing posts.
$ wp post create --from-post=123 --post_title='Different Title'
Success: Created post 2350.

wp post update

Updates one or more existing posts.

Usage

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]

You can specify global options and the following:

{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 . 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.

wp post edit

Launches system editor to edit post content.

Usage

wp post edit {id}

You can specify global options and the following:

{id}
The ID of the post to edit.

Examples

# Launch system editor to edit post
$ wp post edit 123

wp post get

Gets details about a post.

Usage

wp post get {id} [--field={field}] [--fields={fields}] [--format={format}]

You can specify global options and the following:

{id}
The ID of the post to get.
[--field={field}]
Instead of returning the whole post, returns the value of a single field.
[--fields={fields}]
Limit the output to specific fields. Defaults to all fields.
[--format={format}]

Render output in a particular format.
Default: table
Can be:

  • table
  • csv
  • json
  • yaml

Examples

# Save the post content to a file
$ wp post get 123 --field=content > file.txt

wp post delete

Deletes an existing post.

Usage

wp post delete {id}... [--force] [--defer-term-counting]

You can specify global options and the following:

{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 post skipping trash
$ wp post delete 123 124 --force
Success: Deleted post 123.
Success: Deleted post 124.
# 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.

wp post list

Gets a list of posts.

Display posts based on all arguments supported by WP_Query().

Usage

wp post list [--{field}={value}] [--field={field}] [--fields={fields}] [--format={format}]

You can specify global options and the following:

[--{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
Can be:

  • 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     |
+----+--------------+-------------+---------------------+-------------+

wp post generate

Generates some posts.

Creates a specified number of new posts with dummy data.

Usage

wp post generate [--count={number}] [--post_type={type}] [--post_status={status}] [--post_title={post_title}] [--post_author={login}] [--post_date={yyyy-mm-dd-hh-ii-ss}] [--post_date_gmt={yyyy-mm-dd-hh-ii-ss}] [--post_content] [--max_depth={number}] [--format={format}]

You can specify global options and the following:

[--count={number}]
How many posts to generate?
Default: 100
[--post_type={type}]
The type of the generated posts.
Default: post
[--post_status={status}]
The status of the generated posts.
Default: publish
[--post_title={post_title}]
The post title.
default:
[--post_author={login}]
The author of the generated posts.
default:
[--post_date={yyyy-mm-dd-hh-ii-ss}]
The date of the generated posts. Default: current date
[--post_date_gmt={yyyy-mm-dd-hh-ii-ss}]
The GMT date of the generated posts. Default: value of post_date (or current date if it's not set)
[--post_content]
If set, the command reads the post_content from STDIN.
[--max_depth={number}]
For hierarchical post types, generate child posts down to a certain depth.
Default: 1
[--format={format}]

Render output in a particular format.
Default: progress
Can be:

  • progress
  • ids

Examples

# Generate posts.
$ wp post generate --count=10 --post_type=page --post_date=1999-01-04
Generating posts  100% [================================================] 0:01 / 0:04
# Generate posts with fetched content.
$ curl http://loripsum.net/api/5 | wp post generate --post_content --count=10
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
								 Dload  Upload   Total   Spent    Left  Speed
100  2509  100  2509    0     0    616      0  0:00:04  0:00:04 --:--:--   616
Generating posts  100% [================================================] 0:01 / 0:04
# Add meta to every generated posts.
$ wp post generate --format=ids | xargs -d ' ' -I % wp post meta add % foo bar
Success: Added custom field.
Success: Added custom field.
Success: Added custom field.

wp post exists

Verifies whether a post exists.

Displays a success message if the post does exist.

Usage

wp post exists {id}

You can specify global options and the following:

{id}
The ID of the post to check.

Examples

# The post exists.
$ wp post exists 1
Success: Post with ID 1337 exists.
$ echo $?
0
# The post does not exist.
$ wp post exists 10000
$ echo $?
1

wp post meta list

List all metadata associated with an object.

Usage

wp post meta list {id} [--keys={keys}] [--fields={fields}] [--format={format}] [--orderby={fields}] [--order={order}]

You can specify global options and the following:

{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
Can be:

  • table
  • csv
  • json
  • yaml
  • count
[--orderby={fields}]

Set orderby which field.
Default: id
Can be:

  • id
  • meta_key
  • meta_value
[--order={order}]

Set ascending or descending order.
Default: asc
Can be:

  • asc
  • desc

wp post meta get

Get meta field value.

Usage

wp post meta get {id} {key} [--format={format}]

You can specify global options and the following:

{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
Can be:

  • var_export
  • json
  • yaml

wp post meta delete

Delete a meta field.

Usage

wp post meta delete {id} [{key}] [{value}] [--all]

You can specify global options and the following:

{id}
The ID of the object.
[{key}]
The name of the meta field to delete.
[{value}]
The value to delete. If omitted, all rows with key will deleted.
[--all]
Delete all meta for the object.

wp post meta add

Add a meta field.

Usage

wp post meta add {id} {key} [{value}] [--format={format}]

You can specify global options and the following:

{id}
The ID of the object.
{key}
The name of the meta field to create.
[{value}]
The value of the meta field. If omitted, the value is read from STDIN.
[--format={format}]

The serialization format for the value.
Default: plaintext
Can be:

  • plaintext
  • json

wp post meta update

Update a meta field.

Usage

wp post meta update {id} {key} [{value}] [--format={format}]

You can specify global options and the following:

{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
Can be:

  • plaintext
  • json

wp post meta pluck

Get a nested value from a meta field.

Usage

wp post meta pluck {id} {key} {key-path}... [--format={format}]

You can specify global options and the following:

{id}
The ID of the object.
{key}
The name of the meta field to get.
{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
Can be:
  • plaintext
  • json
  • yaml

wp post meta patch

Update a nested value for a meta field.

Usage

wp post meta patch {action} {id} {key} {key-path}... [{value}] [--format={format}]

You can specify global options and the following:

{action}

Patch action to perform.

Can be:

  • 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
Can be:

  • plaintext
  • json

wp post term list

List all terms associated with an object.

Usage

wp post term list {id} {taxonomy}... [--field={field}] [--fields={fields}] [--format={format}]
{id}
ID for the object.
{taxonomy}...
One or more taxonomies to list.
[--field={field}]
Prints the value of a single field for each term.
[--fields={fields}]
Limit the output to specific row fields.
[--format={format}]

Render output in a particular format.
Default: table
Can be:

  • table
  • csv
  • json
  • yaml
  • count
  • ids

Available fields

These fields will be displayed by default for each term:

  • term_id
  • name
  • slug
  • taxonomy

These fields are optionally available:

  • term_taxonomy_id
  • description
  • term_group
  • parent
  • count

wp post term remove

Remove a term from an object.

Usage

wp post term remove {id} {taxonomy} [{term}...] [--by={field}] [--all]

You can specify global options and the following:

{id}
The ID of the object.
{taxonomy}
The name of the term's taxonomy.
[{term}...]
The name of the term or terms to be removed from the object.
[--by={field}]

Explicitly handle the term value as a slug or id.

Can be:

  • slug
  • id
[--all]
Remove all terms from the object.

wp post term add

Add a term to an object.

Append the term to the existing set of terms on the object.

Usage

wp post term add {id} {taxonomy} {term}... [--by={field}]
{id}
The ID of the object.
{taxonomy}
The name of the taxonomy type to be added.
{term}...
The slug of the term or terms to be added.
[--by={field}]

Explicitly handle the term value as a slug or id.

Can be:

  • slug
  • id

wp post term set

Set object terms.

Replaces existing terms on the object.

Usage

wp post term set {id} {taxonomy} {term}... [--by={field}]
{id}
The ID of the object.
{taxonomy}
The name of the taxonomy type to be updated.
{term}...
The slug of the term or terms to be updated.
[--by={field}]

Explicitly handle the term value as a slug or id.

Can be:

  • slug
  • id