wp_create_category( int|string $cat_name, int $category_parent )

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


Parameters

$cat_name

(Required) Category name.

$category_parent

(Optional) ID of parent category.


Return

(int|WP_Error)


Source

File: wp-admin/includes/taxonomy.php

function wp_create_category( $cat_name, $parent = 0 ) {
	if ( $id = category_exists($cat_name, $parent) )
		return $id;

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


Changelog

Changelog
Version Description
2.0.0 Introduced.