public function delete( $args, $assoc_args ) {
		$taxonomy = array_shift( $args );

		$successes = 0;
		$errors    = 0;
		foreach ( $args as $term_id ) {

			$term = $term_id;

			// Get term by specified argument otherwise get term by id.
			$field = Utils\get_flag_value( $assoc_args, 'by' );
			if ( 'slug' === $field ) {

				// Get term by slug.
				$term = get_term_by( $field, $term, $taxonomy );

				// If term not found, then show error message and skip the iteration.
				if ( ! $term ) {
					WP_CLI::warning( "{$taxonomy} {$term_id} doesn't exist." );
					continue;
				}

				// Get the term id;
				$term_id = $term->term_id;

			}

			$result = wp_delete_term( $term_id, $taxonomy );

			if ( is_wp_error( $result ) ) {
				WP_CLI::warning( $result );
				$errors++;
			} elseif ( $result ) {
				WP_CLI::log( "Deleted {$taxonomy} {$term_id}." );
				$successes++;
			} else {
				WP_CLI::warning( "{$taxonomy} {$term_id} doesn't exist." );
			}
		}
		Utils\report_batch_operation_results( 'term', 'delete', count( $args ), $successes, $errors );
	}
public function delete( $args, $assoc_args ) {
		$taxonomy = array_shift( $args );

		$successes = 0;
		$errors    = 0;
		foreach ( $args as $term_id ) {

			$term = $term_id;

			// Get term by specified argument otherwise get term by id.
			$field = Utils\get_flag_value( $assoc_args, 'by' );
			if ( 'slug' === $field ) {

				// Get term by slug.
				$term = get_term_by( $field, $term, $taxonomy );

				// If term not found, then show error message and skip the iteration.
				if ( ! $term ) {
					WP_CLI::warning( "{$taxonomy} {$term_id} doesn't exist." );
					continue;
				}

				// Get the term id;
				$term_id = $term->term_id;

			}

			$result = wp_delete_term( $term_id, $taxonomy );

			if ( is_wp_error( $result ) ) {
				WP_CLI::warning( $result );
				$errors++;
			} elseif ( $result ) {
				WP_CLI::log( "Deleted {$taxonomy} {$term_id}." );
				$successes++;
			} else {
				WP_CLI::warning( "{$taxonomy} {$term_id} doesn't exist." );
			}
		}
		Utils\report_batch_operation_results( 'term', 'delete', count( $args ), $successes, $errors );
	}
public function delete ( $ args , $ assoc_args ) { $ taxonomy = array_shift ( $ args ) ; $ successes = 0 ; $ errors = 0 ; foreach ( $ args as $ term_id ) { $ term = $ term_id ; // Get term by specified argument otherwise get term by id. $ field = Utils \ get_flag_value ( $ assoc_args , 'by' ) ; if ( 'slug' === $ field ) { // Get term by slug. $ term = get_term_by ( $ field , $ term , $ taxonomy ) ; // If term not found, then show error message and skip the iteration. if ( ! $ term ) { WP_CLI :: warning ( "{$taxonomy} {$term_id} doesn't exist." ) ; continue ; } // Get the term id; $ term_id = $ term -> term_id ; } $ result = wp_delete_term ( $ term_id , $ taxonomy ) ; if ( is_wp_error ( $ result ) ) { WP_CLI :: warning ( $ result ) ; $ errors ++ ; } elseif ( $ result ) { WP_CLI :: log ( "Deleted {$taxonomy} {$term_id}." ) ; $ successes ++ ; } else { WP_CLI :: warning ( "{$taxonomy} {$term_id} doesn't exist." ) ; } } Utils \ report_batch_operation_results ( 'term' , 'delete' , count ( $ args ) , $ successes , $ errors ) ; }
Deletes an existing term.

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

## 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.
Deletes an existing term .