WP-CLI create post with custom tax

wp mycpt create --tags='test1,test2'

$tags = null;
if ( isset( $assoc_args['tags'] ) ) {
	$tags = wp_parse_list( $assoc_args['tags'] );
	unset( $assoc_args['tags'] );
}

...

$command = "post create --porcelain " . assoc_args_to_str( $assoc_args );
$id = WP_CLI::runcommand( $command, [ 'return' => true ] );
if ( ! (bool) $id ) {
	WP_CLI::error( 'Post not saved!' );
}
wp_set_object_terms( $id, $tags, TAX_MYCPT_TAG );
WP_CLI::success( sprintf( 'Created post %s.', $id ) );

Revision #4
Created 31 July 2021 10:07:13 by Sander
Updated 31 July 2021 10:15:39 by Sander