Skip to main content

WP-CLI create post with custom tax

$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( 'Bookmark not saved!' );
}
wp_set_object_terms( $id, $tags, TAX_BOOKMARK_TAG );
WP_CLI::success( sprintf( 'Created post %s.', $id ) );