wpseek.com
A WordPress-centric search engine for devs and theme authors



get_the_category_by_id › WordPress Function

Since0.71
Deprecatedn/a
get_the_category_by_id ( $cat_id )
Parameters:
  • (int) $cat_id Category ID.
    Required: Yes
Returns:
  • (string|WP_Error) Category name on success, WP_Error on failure.
Defined at:
Codex:

Retrieves category name based on category ID.



Source

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 : '';
}