get_cat_name

Retrieve the name of a category from its ID.

Description

(string) get_cat_name( (int) $cat_id ); 

Returns (string)

Category name, or an empty string if category doesn't exist.

Parameters (1)

0. $cat_id (int)
The cat id.

Usage

  1. if ( !function_exists( 'get_cat_name' ) ) { 
  2. require_once ABSPATH . WPINC . '/category.php'; 
  3.  
  4. // The cat id. 
  5. $cat_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_cat_name($cat_id); 
  9.  

Defined (1)

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

/wp-includes/category.php  
  1. function get_cat_name( $cat_id ) { 
  2. $cat_id = (int) $cat_id; 
  3. $category = get_term( $cat_id, 'category' ); 
  4. if ( ! $category || is_wp_error( $category ) ) 
  5. return ''; 
  6. return $category->name;