wp_create_term() WordPress Function

The wp_create_term() function is used to create a new term in the WordPress database. This function takes two arguments: the term name and the term slug. The term name is the name of the term, while the term slug is the URL-friendly version of the term name. The function will return the new term object on success, or false on failure.

wp_create_term( string $tag_name, string $taxonomy = 'post_tag' ) #

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


Parameters

$tag_name

(string)(Required)The term name.

$taxonomy

(string)(Optional) The taxonomy within which to create the term.

Default value: 'post_tag'


Top ↑

Return

(array|WP_Error)


Top ↑

Source

File: wp-admin/includes/taxonomy.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.