wp term

Manages taxonomy terms and term meta, with create, delete, and list commands.

See reference for taxonomies and their terms.

Subcommands

Command Description
wp term create Creates a new term.
wp term delete Deletes an existing term.
wp term generate Generates some terms.
wp term get Gets details about a term.
wp term list Lists terms in a taxonomy.
wp term meta Adds, updates, deletes, and lists term custom fields.
wp term migrate Migrate a term of a taxonomy to another taxonomy.
wp term recount Recalculates number of posts assigned to each term.
wp term update Updates an existing term.

wp term create

Creates a new term.

Synopsis

wp term create <taxonomy> <term> [--slug=<slug>] [--description=<description>] [--parent=<term-id>] [--porcelain]

Options

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

Examples

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

wp term delete

Deletes an existing term.

Synopsis

wp term delete <taxonomy> <term>... [--by=<field>]

Options

<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. Default: id. Options: slug, id.

Examples

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

Lists terms in a taxonomy.

Synopsis

wp term list <taxonomy>... [--<field>=<value>] [--field=<field>] [--fields=<fields>] [--format=<format>]

Options

<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. Default: table. Options: table, csv, ids, json, count, yaml.

Available Fields

Default fields: term_id, term_taxonomy_id, name, slug, description, parent, count.

Optional fields: url.

Examples

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

Examples

# 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