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

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


Parameters Parameters

$tag_name

(int|string) (Required)

$taxonomy

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

Default value: 'post_tag'


Top ↑

Return Return

(array|WP_Error)


Top ↑

Source 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

Changelog
Version Description
2.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.