Description
This function adds a "simple" category by specifying a category name and (optionally) a category parent.
Usage
<?php wp_create_category( $cat_name, $parent ); ?>
Parameters
$cat_name
(string) (required) Name for the new category.
Default: None
$parent
(integer) (optional) Category ID of the parent category.
Default: None
Return Values
(boolean)
0 (false) on failure, 1 (true) on success.
Examples
In order to create a simple category use:
wp_create_category('My category name');
To create a category that is a child of Uncategorized (or whatever category has the ID 0), use:
wp_create_category('Child of Uncategorized', 0);
Notes
- 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.
Source File
wp_create_category() is located in wp-admin/includes/taxonomy.php.