category_exists

Check whether a category exists.

Description

category_exists( (string) $cat_name, (null) $parent = null ); 

Parameters (2)

0. $cat_name (string)
Category name.
1. $parent — Optional. (null) => null
ID of parent term.

Usage

  1. if ( !function_exists( 'category_exists' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/taxonomy.php'; 
  3.  
  4. // Category name. 
  5. $cat_name = ''; 
  6.  
  7. // Optional. ID of parent term. 
  8. $parent = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = category_exists($cat_name, $parent); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/taxonomy.php  
  1. function category_exists( $cat_name, $parent = null ) { 
  2. $id = term_exists($cat_name, 'category', $parent); 
  3. if ( is_array($id) ) 
  4. $id = $id['term_id']; 
  5. return $id;