public function generate( $args, $assoc_args ) {
		global $wpdb;

		list ( $taxonomy ) = $args;

		$defaults = [
			'count'     => 100,
			'max_depth' => 1,
		];

		$final_args = array_merge( $defaults, $assoc_args );
		$count      = $final_args['count'];
		$max_depth  = $final_args['max_depth'];

		if ( ! taxonomy_exists( $taxonomy ) ) {
			WP_CLI::error( "'{$taxonomy}' is not a registered taxonomy." );
		}

		$label = get_taxonomy( $taxonomy )->labels->singular_name;
		$slug  = sanitize_title_with_dashes( $label );

		$hierarchical = get_taxonomy( $taxonomy )->hierarchical;

		$format = Utils\get_flag_value( $assoc_args, 'format', 'progress' );

		$notify = false;
		if ( 'progress' === $format ) {
			$notify = Utils\make_progress_bar( 'Generating terms', $count );
		}

		$previous_term_id = 0;
		$current_parent   = 0;
		$current_depth    = 1;

		$max_id = (int) $wpdb->get_var( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} ORDER BY term_taxonomy_id DESC LIMIT 1" );

		$suspend_cache_invalidation = wp_suspend_cache_invalidation( true );
		$created                    = [];

		for ( $index = $max_id + 1; $index <= $max_id + $count; $index++ ) {

			if ( $hierarchical ) {

				if ( $previous_term_id && $this->maybe_make_child() && $current_depth < $max_depth ) {

					$current_parent = $previous_term_id;
					$current_depth++;

				} elseif ( $this->maybe_reset_depth() ) {

					$current_parent = 0;
					$current_depth  = 1;

				}
			}

			$args = [
				'parent' => $current_parent,
				'slug'   => $slug . "-{$index}",
			];

			$name = "{$label} {$index}";
			$term = wp_insert_term( $name, $taxonomy, $args );
			if ( is_wp_error( $term ) ) {
				WP_CLI::warning( $term );
			} else {
				$created[]        = $term['term_id'];
				$previous_term_id = $term['term_id'];
				if ( 'ids' === $format ) {
					echo $term['term_id'];
					if ( $index < $max_id + $count ) {
						echo ' ';
					}
				}
			}

			if ( 'progress' === $format ) {
				$notify->tick();
			}
		}

		wp_suspend_cache_invalidation( $suspend_cache_invalidation );
		clean_term_cache( $created, $taxonomy );

		if ( 'progress' === $format ) {
			$notify->finish();
		}
	}
public function generate( $args, $assoc_args ) {
		global $wpdb;

		list ( $taxonomy ) = $args;

		$defaults = [
			'count'     => 100,
			'max_depth' => 1,
		];

		$final_args = array_merge( $defaults, $assoc_args );
		$count      = $final_args['count'];
		$max_depth  = $final_args['max_depth'];

		if ( ! taxonomy_exists( $taxonomy ) ) {
			WP_CLI::error( "'{$taxonomy}' is not a registered taxonomy." );
		}

		$label = get_taxonomy( $taxonomy )->labels->singular_name;
		$slug  = sanitize_title_with_dashes( $label );

		$hierarchical = get_taxonomy( $taxonomy )->hierarchical;

		$format = Utils\get_flag_value( $assoc_args, 'format', 'progress' );

		$notify = false;
		if ( 'progress' === $format ) {
			$notify = Utils\make_progress_bar( 'Generating terms', $count );
		}

		$previous_term_id = 0;
		$current_parent   = 0;
		$current_depth    = 1;

		$max_id = (int) $wpdb->get_var( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} ORDER BY term_taxonomy_id DESC LIMIT 1" );

		$suspend_cache_invalidation = wp_suspend_cache_invalidation( true );
		$created                    = [];

		for ( $index = $max_id + 1; $index <= $max_id + $count; $index++ ) {

			if ( $hierarchical ) {

				if ( $previous_term_id && $this->maybe_make_child() && $current_depth < $max_depth ) {

					$current_parent = $previous_term_id;
					$current_depth++;

				} elseif ( $this->maybe_reset_depth() ) {

					$current_parent = 0;
					$current_depth  = 1;

				}
			}

			$args = [
				'parent' => $current_parent,
				'slug'   => $slug . "-{$index}",
			];

			$name = "{$label} {$index}";
			$term = wp_insert_term( $name, $taxonomy, $args );
			if ( is_wp_error( $term ) ) {
				WP_CLI::warning( $term );
			} else {
				$created[]        = $term['term_id'];
				$previous_term_id = $term['term_id'];
				if ( 'ids' === $format ) {
					echo $term['term_id'];
					if ( $index < $max_id + $count ) {
						echo ' ';
					}
				}
			}

			if ( 'progress' === $format ) {
				$notify->tick();
			}
		}

		wp_suspend_cache_invalidation( $suspend_cache_invalidation );
		clean_term_cache( $created, $taxonomy );

		if ( 'progress' === $format ) {
			$notify->finish();
		}
	}
public function generate ( $ args , $ assoc_args ) { global $ wpdb ; list ( $ taxonomy ) = $ args ; $ defaults = [ 'count' => 100 , 'max_depth' => 1 , ] ; $ final_args = array_merge ( $ defaults , $ assoc_args ) ; $ count = $ final_args [ 'count' ] ; $ max_depth = $ final_args [ 'max_depth' ] ; if ( ! taxonomy_exists ( $ taxonomy ) ) { WP_CLI :: error ( "'{$taxonomy}' is not a registered taxonomy." ) ; } $ label = get_taxonomy ( $ taxonomy ) -> labels -> singular_name ; $ slug = sanitize_title_with_dashes ( $ label ) ; $ hierarchical = get_taxonomy ( $ taxonomy ) -> hierarchical ; $ format = Utils \ get_flag_value ( $ assoc_args , 'format' , 'progress' ) ; $ notify = false ; if ( 'progress' === $ format ) { $ notify = Utils \ make_progress_bar ( 'Generating terms' , $ count ) ; } $ previous_term_id = 0 ; $ current_parent = 0 ; $ current_depth = 1 ; $ max_id = ( int ) $ wpdb -> get_var ( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} ORDER BY term_taxonomy_id DESC LIMIT 1" ) ; $ suspend_cache_invalidation = wp_suspend_cache_invalidation ( true ) ; $ created = [ ] ; for ( $ index = $ max_id + 1 ; $ index <= $ max_id + $ count ; $ index ++ ) { if ( $ hierarchical ) { if ( $ previous_term_id && $ this -> maybe_make_child ( ) && $ current_depth < $ max_depth ) { $ current_parent = $ previous_term_id ; $ current_depth ++ ; } elseif ( $ this -> maybe_reset_depth ( ) ) { $ current_parent = 0 ; $ current_depth = 1 ; } } $ args = [ 'parent' => $ current_parent , 'slug' => $ slug . "-{$index}" , ] ; $ name = "{$label} {$index}" ; $ term = wp_insert_term ( $ name , $ taxonomy , $ args ) ; if ( is_wp_error ( $ term ) ) { WP_CLI :: warning ( $ term ) ; } else { $ created [ ] = $ term [ 'term_id' ] ; $ previous_term_id = $ term [ 'term_id' ] ; if ( 'ids' === $ format ) { echo $ term [ 'term_id' ] ; if ( $ index < $ max_id + $ count ) { echo ' ' ; } } } if ( 'progress' === $ format ) { $ notify -> tick ( ) ; } } wp_suspend_cache_invalidation ( $ suspend_cache_invalidation ) ; clean_term_cache ( $ created , $ taxonomy ) ; if ( 'progress' === $ format ) { $ notify -> finish ( ) ; } }
Generates some terms.

Creates a specified number of new terms with dummy data.

## OPTIONS

<taxonomy>
: The taxonomy for the generated terms.

[--count=<number>]
: How many terms to generate?
---
default: 100
---

[--max_depth=<number>]
: Generate child terms down to a certain depth.
---
default: 1
---

[--format=<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.
Generates some terms .