On this page
category_exists( int|string $cat_name, int $category_parent = null ): string|null
Checks whether a category exists.
Description
See also
Parameters
$cat_nameint|string Required-
Category name.
$category_parentint Optional-
ID of parent category.
Default:
null
Return
string|null Returns the category ID as a numeric string if the pairing exists, null if not.
Source
File: wp-admin/includes/taxonomy.php. View all references
function category_exists( $cat_name, $category_parent = null ) {
$id = term_exists( $cat_name, 'category', $category_parent );
if ( is_array( $id ) ) {
$id = $id['term_id'];
}
return $id;
}
Related
Uses
| Uses | Description |
|---|---|
| term_exists() wp-includes/taxonomy.php | Determines whether a taxonomy term exists. |
Used By
| Used By | Description |
|---|---|
| wp_create_category() wp-admin/includes/taxonomy.php | Adds a new category to the database if it does not already exist. |
| wp_create_categories() wp-admin/includes/taxonomy.php | Creates categories for the given post. |
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/category_exists