wp post
Manages posts, content, and meta.
Subcommands
| Command | Description |
|---|---|
wp post create |
Creates a new post. |
wp post delete |
Deletes an existing post. |
wp post edit |
Launches system editor to edit post content. |
wp post exists |
Verifies whether a post exists. |
wp post generate |
Generates some posts. |
wp post get |
Gets details about a post. |
wp post list |
Gets a list of posts. |
wp post meta |
Adds, updates, deletes, and lists post custom fields. |
wp post term |
Adds, updates, removes, and lists post terms. |
wp post update |
Updates one or more existing posts. |
wp post url-to-id |
Gets the post ID for a given URL. |
wp post create
Creates a new post.
Synopsis
wp post create [--post_author=<post_author>] [--post_date=<post_date>] [--post_content=<post_content>] [--post_title=<post_title>] [--post_excerpt=<post_excerpt>] [--post_status=<post_status>] [--post_type=<post_type>] [--post_name=<post_name>] [--from-post=<post_id>] [--post_parent=<post_parent>] [--menu_order=<menu_order>] [--post_category=<post_category>] [--tags_input=<tags_input>] [--tax_input=<tax_input>] [--meta_input=<meta_input>] [<file>] [--edit] [--porcelain]
Options
[--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_content=<post_content>]
: The 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’.
[--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.
[--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_category=<post_category>]
: Array of category names, slugs, or IDs.
[--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.
[<file>]
: Read post content from file. Passing - as the filename will cause post content to be read from STDIN.
[--edit]
: Immediately open system’s editor to write or edit post content.
[--porcelain]
: Output just the new post id.
Examples
# Create post and schedule for future
$ wp post create --post_type=post --post_title='A future post' --post_status=future --post_date='2030-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 delete
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 multiple posts
$ wp post delete 123 456 789
Success: Trashed post 123.
Success: Trashed post 456.
Success: Trashed post 789.
# Delete all pages
$ wp post delete $(wp post list --post_type='page' --format=ids)
Success: Trashed post 1164.
Success: Trashed post 1186.
wp post edit
Launches system editor to edit post content.
Synopsis
wp post edit <id>
Examples
$ wp post edit 123
wp post exists
Verifies whether a post exists.
Synopsis
wp post exists <id>
Examples
# The post exists.
$ wp post exists 1337
Success: Post with ID 1337 exists.
$ echo $?
0
# The post does not exist.
$ wp post exists 10000
$ echo $?
1
wp post generate
Generates some posts. Creates a specified number of new posts with dummy data.
Synopsis
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_content] [--max_depth=<number>] [--format=<format>]
Options
[--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 empty.
[--post_author=<login>]
: The author of the generated posts.
[--post_date=<yyyy-mm-dd-hh-ii-ss>]
: The date of the post. Default is the current time.
[--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 (progress, ids). Default: progress
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 -N https://loripsum.net/api/5 | wp post generate --post_content --count=10
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.
wp post get
Gets details about a post.
Synopsis
wp post get <id> [--field=<field>] [--fields=<fields>] [--format=<format>]
Options
<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 (table, csv, json, yaml).
Examples
# Save the post content to a file
$ wp post get 123 --field=content > file.txt
wp post list
Gets a list of posts. Display posts based on all arguments supported by WP_Query().
Synopsis
wp post list [--<field>=<value>] [--field=<field>] [--fields=<fields>] [--format=<format>]
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 (table, csv, ids, json, count, yaml).
Available Fields
Default: ID, post_title, post_name, post_date, post_status
Optional: 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
# List all pages
$ wp post list --post_type=page --fields=post_title,post_status
# List ids of all pages and posts
$ wp post list --post_type=page,post --format=ids
15 25 34 37 198
wp post meta
Adds, updates, deletes, and lists post custom fields.
Subcommands
| Command | Description |
|---|---|
wp post meta add |
Add a meta field. |
wp post meta clean-duplicates |
Cleans up duplicate post meta values on a post. |
wp post meta delete |
Delete a meta field. |
wp post meta get |
Get meta field value. |
wp post meta list |
List all metadata associated with an object. |
wp post meta patch |
Update a nested value for a meta field. |
wp post meta pluck |
Get a nested value from a meta field. |
wp post meta 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.
wp post term
Adds, updates, removes, and lists post terms.
Subcommands
| Command | Description |
|---|---|
wp post term add |
Add a term to an object. |
wp post term list |
List all terms associated with an object. |
wp post term remove |
Remove a term from an object. |
wp post term set |
Set object terms. |
Examples
# Set category post term `test` to the post ID 123
$ wp post term set 123 test category
Success: Set term.
# Set category post terms `test` and `apple` to the post ID 123
$ wp post term set 123 test apple category
Success: Set terms.
# List category post terms for the post ID 123
$ wp post term list 123 category --fields=term_id,slug
+---------+-------+
| term_id | slug |
+---------+-------+
| 2 | apple |
| 3 | test |
+----------+------+
# Remove category post terms `test` and `apple` for the post ID 123
$ wp post term remove 123 category test apple
Success: Removed terms.
wp post update
Updates one or more existing posts.
Synopsis
wp post update <id>... [--post_author=<post_author>] [--post_date=<post_date>] [--post_content=<post_content>] [--post_title=<post_title>] [--post_excerpt=<post_excerpt>] [--post_status=<post_status>] [--post_type=<post_type>] [--post_name=<post_name>] [--post_parent=<post_parent>] [--menu_order=<menu_order>] [--post_category=<post_category>] [--tags_input=<tags_input>] [--tax_input=<tax_input>] [--meta_input=<meta_input>] [<file>] [--defer-term-counting]
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.
# Update multiple posts at once.
$ wp post update 123 456 --post_author=789
Success: Updated post 123.
Success: Updated post 456.
# Update all posts of a given post type at once.
$ wp post update $(wp post list --post_type=page --format=ids) --post_author=123
Success: Updated post 123.
Success: Updated post 456.
wp post url-to-id
Gets the post ID for a given URL.
Synopsis
wp post url-to-id <url>
Examples
$ wp post url-to-id https://example.com/?p=1
1