W3cubDocs

/WordPress

wp_create_term( int|string $tag_name, string $taxonomy = 'post_tag' )

Add a new term to the database if it does not already exist.

Description

Parameters

$tag_name

(int|string) (Required)

$taxonomy

(string) (Optional) The taxonomy for which to retrieve terms.

Default value: 'post_tag'

Return

(array|WP_Error)

Source

File: wp-admin/includes/taxonomy.php

function wp_create_term( $tag_name, $taxonomy = 'post_tag' ) {
	if ( $id = term_exists( $tag_name, $taxonomy ) ) {
		return $id;
	}

	return wp_insert_term( $tag_name, $taxonomy );
}

Changelog

Version Description
2.8.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_create_term