PHP Class Term_Command, wp-cli

Inheritance: extends WP_CLI_Command
Show file Open project: wp-cli/wp-cli

Public Methods

Method Description
create ( $args, $assoc_args ) Create a new term.
delete ( $args ) Delete an existing term.
generate ( $args, $assoc_args ) Generate some terms.
get ( $args, $assoc_args ) Get details about a term.
list_ ( $args, $assoc_args ) List terms in a taxonomy.
recount ( $args ) Recalculate number of posts assigned to each term.
update ( $args, $assoc_args ) Update an existing term.

Private Methods

Method Description
get_formatter ( &$assoc_args )
maybe_make_child ( )
maybe_reset_depth ( )

Method Details

create() public method

## OPTIONS : Taxonomy for the new term. : A name for the new term. [--slug=] : A unique slug for the new term. Defaults to sanitized version of name. [--description=] : A description for the new term. [--parent=] : 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.
public create ( $args, $assoc_args )

delete() public method

Errors if the term doesn't exist, or there was a problem in deleting it. ## OPTIONS : Taxonomy of the term to delete. ... : One or more IDs of terms to delete. ## EXAMPLES # Delete post category $ wp term delete category 15 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.
public delete ( $args )

generate() public method

Creates a specified number of new terms with dummy data. ## OPTIONS : The taxonomy for the generated terms. [--count=] : How many terms to generate? --- default: 100 --- [--max_depth=] : Generate child terms down to a certain depth. --- default: 1 --- [--format=] : Render output in a particular format. --- default: progress options: - progress - ids --- ## EXAMPLES # 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.
public generate ( $args, $assoc_args )

get() public method

## OPTIONS : Taxonomy of the term to get : ID of the term to get [--field=] : Instead of returning the whole term, returns the value of a single field. [--fields=] : Limit the output to specific fields. Defaults to all fields. [--format=] : Render output in a particular format. --- default: table options: - table - csv - json - yaml --- ## EXAMPLES # 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"}
public get ( $args, $assoc_args )

list_() public method

## OPTIONS ... : List terms of one or more taxonomies [--=] : Filter by one or more fields (see get_terms() $args parameter for a list of fields). [--field=] : Prints the value of a single field for each term. [--fields=] : Limit the output to specific object fields. [--format=] : Render output in a particular format. --- default: table options: - table - csv - ids - json - count - yaml --- ## AVAILABLE FIELDS 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 ## 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 | +-----------+-------------+
public list_ ( $args, $assoc_args )

recount() public method

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. ## OPTIONS ... : One or more taxonomies to recalculate. ## EXAMPLES # 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.
public recount ( $args )

update() public method

## OPTIONS : Taxonomy of the term to update. : ID for the term to update. [--name=] : A new name for the term. [--slug=] : A new slug for the term. [--description=] : A new description for the term. [--parent=] : A new parent for the term. ## EXAMPLES # Change category with id 15 to use the name "Apple" $ wp term update category 15 --name=Apple Success: Term updated.
public update ( $args, $assoc_args )