wpseek.com
A WordPress-centric search engine for devs and theme authors



category_exists › WordPress Function

Since2.0.0
Deprecatedn/a
category_exists ( $cat_name, $category_parent = null )
Parameters: (2)
  • (int|string) $cat_name Category name.
    Required: Yes
  • (int) $category_parent Optional. ID of parent category.
    Required: No
    Default: null
See:
Returns:
  • (string|null) Returns the category ID as a numeric string if the pairing exists, null if not.
Defined at:
Codex:

Checks whether a category exists.



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;
}