Checks whether a category exists.
Description
See also
Parameters
$cat_name
int|stringrequired- Category name.
$category_parent
intoptional- ID of parent category.
Default:
null
Source
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. |
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.