Title: get_the_category_by_ID
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_the_category_by_ID( int $cat_id ): string|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#user-contributed-notes)

Retrieves category name based on category ID.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#parameters)󠁿

 `$cat_id`intrequired

Category ID.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#return)󠁿

 string|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) 
Category name on success, [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#source)󠁿

    ```php
    function get_the_category_by_ID( $cat_id ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
    	$cat_id   = (int) $cat_id;
    	$category = get_term( $cat_id );

    	if ( is_wp_error( $category ) ) {
    		return $category;
    	}

    	return ( $category ) ? $category->name : '';
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/category-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/category-template.php#L109)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/category-template.php#L109-L118)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#related)󠁿

| Uses | Description | 
| [get_term()](https://developer.wordpress.org/reference/functions/get_term/)`wp-includes/taxonomy.php` |

Gets all term data from database by term ID.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

| Used by | Description | 
| [the_category_head()](https://developer.wordpress.org/reference/functions/the_category_head/)`wp-includes/deprecated.php` |

Prints a category with optional text before and after.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#changelog)󠁿

| Version | Description | 
| [0.71](https://developer.wordpress.org/reference/since/0.71/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/get_the_category_by_ID/?output_format=md#comment-content-5554)
 2.   [Monzur Alam](https://profiles.wordpress.org/monzuralam/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/get_the_category_by_id/#comment-5554)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_category_by_id%2F%23comment-5554)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_category_by_id%2F%23comment-5554)
 4. **Basic Example**
 5.     ```php
        <?php echo get_the_category_by_ID( 'category_id_here' ); ?>
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_category_by_id%2F%3Freplytocom%3D5554%23feedback-editor-5554)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_the_category_by_id%2F)
before being able to contribute a note or feedback.