wp_create_category( int|string $cat_name, int $parent )
Add a new category to the database if it does not already exist.
Description Description
Parameters Parameters
- $cat_name
-
(int|string) (Required)
- $parent
-
(int) (Required)
Return Return
(int|WP_Error)
Source 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, ) ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Examples
In order to create a simple category use:
To create a category that is a child of Uncategorized (or whatever category has the ID 0), use:
To get id of category created and put value in variable: