get_cat_ID

Retrieve the ID of a category from its name.

Description

(int) get_cat_ID( (string) $cat_name ); 

Returns (int)

0, if failure and ID of category on success.

Parameters (1)

0. $cat_name (string)
Category name.

Usage

  1. if ( !function_exists( 'get_cat_ID' ) ) { 
  2. require_once ABSPATH . WPINC . '/category.php'; 
  3.  
  4. // Category name. 
  5. $cat_name = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_cat_ID($cat_name); 
  9.  

Defined (1)

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

/wp-includes/category.php  
  1. function get_cat_ID( $cat_name ) { 
  2. $cat = get_term_by( 'name', $cat_name, 'category' ); 
  3. if ( $cat ) 
  4. return $cat->term_id; 
  5. return 0;