wp_create_term()WP 2.8.0

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

Хуков нет.

Возвращает

Массив|WP_Error.

Использование

wp_create_term( $tag_name, $taxonomy );
$tag_name(строка) (обязательный)
The term name.
$taxonomy(строка)
The taxonomy within which to create the term.
По умолчанию: 'post_tag'

Список изменений

С версии 2.8.0 Введена.

Код wp_create_term() WP 6.5.2

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