WordPress at a glance

wp_create_category() WP 1.0

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

Возвращает

Int/WP_Error.

Works based on: wp_insert_category()

No Hooks.

Usage

wp_create_category( $cat_name, $parent );
$cat_name(int/string) (required)
$parent(int)

Default: 0

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

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

Code of wp_create_category() WP 5.5.1

wp-admin/includes/taxonomy.php
<?php
function wp_create_category( $cat_name, $parent = 0 ) {
	$id = category_exists( $cat_name, $parent );
	if ( $id ) {
		return $id;
	}

	return wp_insert_category(
		array(
			'cat_name'        => $cat_name,
			'category_parent' => $parent,
		)
	);
}

Related Functions

From category: Categories

No comments
    Log In . Register