A WordPress-centric search engine for devs and theme authors



wp_create_category ›

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

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



Source

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