get_the_category_by_ID( int $cat_ID )

Retrieves category name based on category ID.

Parameters

$cat_ID

(int) (Required) Category ID.

Return

(string|WP_Error) Category name on success, WP_Error on failure.

Source

File: wp-includes/category-template.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 : '';
}

Changelog

Version Description
0.71 Introduced.

© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_the_category_by_id