get_the_category_by_ID

Retrieve category name based on category ID.

Description

(string|WP_Error) get_the_category_by_ID( (int) $cat_ID ); 

Returns (string|WP_Error)

Category name on success, WP_Error on failure.

Parameters (1)

0. $cat_id (int)
Category ID.

Usage

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

Defined (1)

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

/wp-includes/category-template.php  
  1. function get_the_category_by_ID( $cat_ID ) { 
  2. $cat_ID = (int) $cat_ID; 
  3. $category = get_term( $cat_ID, 'category' ); 
  4.  
  5. if ( is_wp_error( $category ) ) 
  6. return $category; 
  7.  
  8. return ( $category ) ? $category->name : '';