Uses
Uses | Description |
---|---|
wp-admin/includes/taxonomy.php: category_exists() | Check whether a category exists. |
wp-admin/includes/taxonomy.php: wp_insert_category() | Updates an existing Category or creates a new Category. |
Add a new category to the database if it does not already exist.
(int|string) (Required)
(int) (Required)
(int|WP_Error)
Parameters:
$cat_name
: Name for the new category.$parent
: Category ID of the parent category.Returns:
wp_create_category() is a thin wrapper around wp_insert_category().
Because this is a wrapper, it is not suitable for entering a complex custom taxonomy element.
If the category already exists, it is not duplicated. The ID of the original existing category is returned without error.
File: wp-admin/includes/taxonomy.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, ) ); }
Version | Description |
---|---|
2.0.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_create_category