wp term

Управляет терминами таксономии и терминами meta с помощью команд create, delete и list.

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

Примеры

# Create a new term.
$ wp term create category Apple --description="A type of fruit"
Success: Created category 199.

# Get details about a term.
$ wp term get category 199 --format=json --fields=term_id,name,slug,count
{"term_id":199,"name":"Apple","slug":"apple","count":1}

# Update an existing term.
$ wp term update category 15 --name=Apple
Success: Term updated.

# Get the term's URL.
$ wp term list post_tag --include=123 --field=url
http://example.com/tag/tips-and-tricks

# Delete post category
$ wp term delete category 15
Success: Deleted category 15.

# Recount posts assigned to each categories and tags
$ wp term recount category post_tag
Success: Updated category term count
Success: Updated post_tag term count

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


wp term list

Получает термины таксономии.

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

wp term list {taxonomy}... [--{field}={value}] [--field={field}] [--fields={fields}]
[--format={format}]

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

{taxonomy}...
List terms of one or more taxonomies
[--{field}={value}]
Filter by one or more fields (see get_terms() $args parameter for a list of fields).
[--field={field}]
Prints the value of a single field for each term.
[--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 term:

  • term_id
  • term_taxonomy_id
  • name
  • slug
  • description
  • parent
  • count

These fields are optionally available:

  • url

Примеры

# List post categories
$ wp term list category --format=csv
term_id,term_taxonomy_id,name,slug,description,parent,count
2,2,aciform,aciform,,0,1
3,3,antiquarianism,antiquarianism,,0,1
4,4,arrangement,arrangement,,0,1
5,5,asmodeus,asmodeus,,0,1
# List post tags
$ wp term list post_tag --fields=name,slug
+-----------+-------------+
| name      | slug        |
+-----------+-------------+
| 8BIT      | 8bit        |
| alignment | alignment-2 |
| Articles  | articles    |
| aside     | aside       |
+-----------+-------------+

wp term create

Создает новый термин.

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

wp term create {taxonomy} {term} [--slug={slug}] [--description={description}] [--parent={term-id}]
[--porcelain]

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

{taxonomy}
Taxonomy for the new term.
{term}
A name for the new term.
[--slug={slug}]
A unique slug for the new term. Defaults to sanitized version of name.
[--description={description}]
A description for the new term.
[--parent={term-id}]
A parent for the new term.
[--porcelain]
Output just the new term id.

Примеры

# Create a new category "Apple" with a description.
$ wp term create category Apple --description="A type of fruit"
Success: Created category 199.

wp term get

Получает сведения о термине.

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

wp term get {taxonomy} {term} [--by={field}] [--field={field}] [--fields={fields}]
[--format={format}]

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

{taxonomy}
Taxonomy of the term to get
{term}
ID or slug of the term to get
[--by={field}]

Explicitly handle the term value as a slug or id.
По умолчанию: id
Может быть:

  • slug
  • id
[--field={field}]
Instead of returning the whole term, 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

Примеры

# Get details about a category with id 199.
$ wp term get category 199 --format=json
{"term_id":199,"name":"Apple","slug":"apple","term_group":0,"term_taxonomy_id":199,"taxonomy":"category","description":"A type of fruit","parent":0,"count":0,"filter":"raw"}
# Get details about a category with slug apple.
$ wp term get category apple --by=slug --format=json
{"term_id":199,"name":"Apple","slug":"apple","term_group":0,"term_taxonomy_id":199,"taxonomy":"category","description":"A type of fruit","parent":0,"count":0,"filter":"raw"}

wp term update

Обновляет существующий термин.

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

wp term update {taxonomy} {term} [--by={field}] [--name={name}] [--slug={slug}]
[--description={description}] [--parent={term-id}]

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

{taxonomy}
Taxonomy of the term to update.
{term}
ID or slug for the term to update.
[--by={field}]

Explicitly handle the term value as a slug or id.
По умолчанию: id
Может быть:

  • slug
  • id
[--name={name}]
A new name for the term.
[--slug={slug}]
A new slug for the term.
[--description={description}]
A new description for the term.
[--parent={term-id}]
A new parent for the term.

Примеры

# Change category with id 15 to use the name "Apple"
$ wp term update category 15 --name=Apple
Success: Term updated.
# Change category with slug apple to use the name "Apple"
$ wp term update category apple --by=slug --name=Apple
Success: Term updated.

wp term delete

Удаляет существующий термин.

Errors if the term doesn't exist, or there was a problem in deleting it.

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

wp term delete {taxonomy} {term}... [--by={field}]

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

{taxonomy}
Taxonomy of the term to delete.
{term}...
One or more IDs or slugs of terms to delete.
[--by={field}]

Explicitly handle the term value as a slug or id.
По умолчанию: id
Может быть:

  • slug
  • id

Примеры

# Delete post category by id
$ wp term delete category 15
Deleted category 15.
Success: Deleted 1 of 1 terms.
# Delete post category by slug
$ wp term delete category apple --by=slug
Deleted category 15.
Success: Deleted 1 of 1 terms.
# Delete all post tags
$ wp term list post_tag --field=term_id | xargs wp term delete post_tag
Deleted post_tag 159.
Deleted post_tag 160.
Deleted post_tag 161.
Success: Deleted 3 of 3 terms.

wp term generate

Генерирует термины.

Creates a specified number of new terms with dummy data.

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

wp term generate {taxonomy} [--count={number}] [--max_depth={number}] [--format={format}]

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

{taxonomy}
The taxonomy for the generated terms.
[--count={number}]
How many terms to generate?
По умолчанию: 100
[--max_depth={number}]
Generate child terms down to a certain depth.
По умолчанию: 1
[--format={format}]

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

  • progress
  • ids

Примеры

# Generate post categories.
$ wp term generate category --count=10
Generating terms  100% [=========] 0:02 / 0:02
# Add meta to every generated term.
$ wp term generate category --format=ids --count=3 | xargs -d ' ' -I % wp term meta add % foo bar
Success: Added custom field.
Success: Added custom field.
Success: Added custom field.

wp term recount

Пересчитывает количество записей в каждом термине.

In instances where manual updates are made to the terms assigned to posts in the database, the number of posts associated with a term can become out-of-sync with the actual number of posts.

This command runs wp_update_term_count() on the taxonomy's terms to bring the count back to the correct value.

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

wp term recount {taxonomy}...

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

{taxonomy}...
One or more taxonomies to recalculate.

Примеры

# Recount posts assigned to each categories and tags
$ wp term recount category post_tag
Success: Updated category term count.
Success: Updated post_tag term count.
# Recount all listed taxonomies
$ wp taxonomy list --field=name | xargs wp term recount
Success: Updated category term count.
Success: Updated post_tag term count.
Success: Updated nav_menu term count.
Success: Updated link_category term count.
Success: Updated post_format term count.

wp term meta list

Список всех метаданных, связанных с объектом.

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

wp term 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

wp term meta get

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

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

wp term 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 term meta delete

Удаляет мета-поле.

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

wp term 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 term meta add

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

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

wp term 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 term meta update

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

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

wp term 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 term meta pluck

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

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

wp term 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 term meta patch

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

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

wp term 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