get_the_category_by_ID()
Retrieve category name based on category ID.
Uses: get_term()
No Hooks.
Return
String|WP_Error
. Category name on success, WP_Error on failure.
Usage
get_the_category_by_ID( $cat_id );
- $cat_id(int) (required)
- Category ID.
Examples
#1 Let category 7 be named "Author Functions". Get this name by ID: [auto-translate]
$cat_name = get_the_category_by_ID( 7 ); echo $cat_name; // outputs: Author's Functions
Changelog
Since 0.71 | Introduced. |
get_the_category_by_ID() get the category by ID code WP 6.7.1
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 : ''; }