get_the_category_by_ID() WordPress Function

The get_the_category_by_ID() function is used to get a category object by its ID.

get_the_category_by_ID( int $cat_id ) #

Retrieves category name based on category ID.


Parameters

$cat_id

(int)(Required)Category ID.


Top ↑

Return

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


Top ↑

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


Top ↑

Changelog

Changelog
VersionDescription
0.71Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.