category_exists( int|string $cat_name, int $category_parent = null ): string|null
Checks whether a category exists.
Contents
Description
See also
Parameters
-
$cat_name
int|string Required -
Category name.
-
$category_parent
int 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;
}
Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Beware this function is only available in the wp-admin and will throw an error if used in the front end of your site. Use term_exists instead.