wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_create_term › WordPress Function

Since2.8.0
Deprecatedn/a
wp_create_term ( $tag_name, $taxonomy = 'post_tag' )
Parameters: (2)
  • (string) $tag_name The term name.
    Required: Yes
  • (string) $taxonomy Optional. The taxonomy within which to create the term. Default 'post_tag'.
    Required: No
    Default: 'post_tag'
Returns:
  • (array|WP_Error)
Defined at:
Codex:

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



Source

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

	return wp_insert_term( $tag_name, $taxonomy );
}