WordPress at a glance

get_the_category_by_ID() WP 1.0

Retrieve category name based on category ID.

Works based on: get_term()

No Hooks.

Return

String/WP_Error. Category name on success, WP_Error on failure.

Usage

get_the_category_by_ID( $cat_ID ) // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid;
$cat_ID(int) (required)
Category ID.

Changelog

Since 0.71 Introduced.

Code of get the category by ID: wp-includes/category-template.php WP 5.3.2

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

Related Functions

From category: Categories

No comments
        Log In . Register