wp post

Управление записями: контентом, метаданными, таксономиями записей и т.д.

Список команд Описание
wp post create Создает новую запись.
wp post update Обновляет одну или несколько существующих записей.
wp post edit Запускает системный редактор для редактирования содержимого записи.
wp post get Получает сведения о записи.
wp post delete Удаляет существующую запись.
wp post list Получает список записей.
wp post generate Создает несколько записей.
wp post meta list Список всех мета-полей записи.
wp post meta get Получает значение мета-поля.
wp post meta delete Удаление мета-поле.
wp post meta add Добавляет мета-поле.
wp post meta update Обновляет мета-поля.
wp post meta pluck Получает вложенное значение из мета-поля (из сериал-го массива).
wp post meta patch Обновление вложенного значения мета-поля (сериал-го массива).
wp post term list Список всех терминов, связанных с записью.
wp post term remove Открепляет запись от термина.
wp post term add Прикрепляет запись к термину.
wp post term set Устанавливает термины записи.

Примеры

Посты

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

Метаданные постов

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

Термины постов

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

Исходный код команд


wp post create

Создает новую запись.

Использование

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]

Можно указать Глобальные параметры и следующие:

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

Примеры

# 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

Обновляет одну или несколько существующих записей.

Использование

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]

Можно указать Глобальные параметры и следующие:

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

Примеры

$ 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

Запускает системный редактор для редактирования содержимого записи.

Использование

wp post edit {id}

Можно указать Глобальные параметры и следующие:

{id}
The ID of the post to edit.

Примеры

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

wp post get

Получает сведения о записи.

Использование

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

Можно указать Глобальные параметры и следующие:

{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
Может быть:

  • table
  • csv
  • json
  • yaml

Примеры

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

wp post delete

Удаляет существующую запись.

Использование

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

Можно указать Глобальные параметры и следующие:

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

Примеры

# 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

Получает список записей.

Использование

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

Можно указать Глобальные параметры и следующие:

[--{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
Может быть:

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

Доступные поля

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

Примеры

# 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

Создает несколько записей.

Creates a specified number of new posts with dummy data.

Использование

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}]

Можно указать Глобальные параметры и следующие:

[--count={number}]
How many posts to generate?
По умолчанию: 100
[--post_type={type}]
The type of the generated posts.
По умолчанию: post
[--post_status={status}]
The status of the generated posts.
По умолчанию: 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. По умолчанию: current date
[--post_date_gmt={yyyy-mm-dd-hh-ii-ss}]
The GMT date of the generated posts. По умолчанию: 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.
По умолчанию: 1
[--format={format}]

Render output in a particular format.
По умолчанию: progress
Может быть:

  • progress
  • ids

Примеры

# 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 meta list

Список всех мета-полей записи.

Использование

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

Можно указать Глобальные параметры и следующие:

{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.
По умолчанию: table
Может быть:

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

Set orderby which field.
По умолчанию: id
Может быть:

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

Set ascending or descending order.
По умолчанию: asc
Может быть:

  • asc
  • desc

Примеры

## Получим все метаполя записи 18 у сайта сети woman.example.com
wp post meta list 18 --url=woman.example.com

wp post meta get

Получает значение мета-поля.

Использование

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

Можно указать Глобальные параметры и следующие:

{id}
The ID of the object.
{key}
The name of the meta field to get.
[--format={format}]

Get value in a particular format.
По умолчанию: var_export
Может быть:

  • var_export
  • json
  • yaml

wp post meta delete

Удаление мета-поле.

Использование

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

Можно указать Глобальные параметры и следующие:

{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

Добавляет мета-поле.

Использование

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

Можно указать Глобальные параметры и следующие:

{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.
По умолчанию: plaintext
Может быть:

  • plaintext
  • json

wp post meta update

Обновляет мета-поля.

Использование

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

Можно указать Глобальные параметры и следующие:

{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.
По умолчанию: plaintext
Может быть:

  • plaintext
  • json

Примеры

$ wp post meta update 5958 "post_date_en" "2021-01-13 00:38:29"
Success: Updated custom field 'post_date_en'.

wp post meta pluck

Получает вложенное значение из мета-поля (из сериал-го массива).

Использование

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

Можно указать Глобальные параметры и следующие:

{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.
По умолчанию: plaintext
Может быть:

  • plaintext
  • json
  • yaml

Примеры

Смотрите здесь

wp post meta patch

Обновление вложенного значения мета-поля (сериал-го массива).

Использование

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

Можно указать Глобальные параметры и следующие:

{action}

Patch action to perform.

Может быть:

  • 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.
По умолчанию: plaintext
Может быть:

  • plaintext
  • json

Примеры

Смотрите здесь

wp post term list

Список всех терминов, связанных с записью.

Использование

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.
По умолчанию: table
Может быть:

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

Доступные поля

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

Открепляет запись от термина.

Использование

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

Можно указать Глобальные параметры и следующие:

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

Может быть:

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

wp post term add

Прикрепляет запись к термину.

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

Использование

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.

Может быть:

  • slug
  • id

wp post term set

Устанавливает термины записи.

Replaces existing terms on the object.

Использование

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.

Может быть:

  • slug
  • id