wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_create_category › WordPress Function

Since2.0.0
Deprecatedn/a
wp_create_category ( $cat_name, $category_parent = 0 )
Parameters: (2)
  • (int|string) $cat_name Category name.
    Required: Yes
  • (int) $category_parent Optional. ID of parent category.
    Required: No
    Default:
Returns:
  • (int|WP_Error)
Defined at:
Codex:

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



Source

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

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