get_the_category_by_ID()

最后更新于:2021-11-27 01:41:47

get_the_category_by_ID( int$cat_ID)

Retrieves category name based on category ID.

参数

$cat_ID

(int) (Required) Category ID.

响应

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

源文件

文件: gc-includes/category-template.php

function get_the_category_by_ID( $cat_ID ) { // phpcs:ignore GeChiUI.NamingConventions.ValidFunctionName.FunctionNameInvalid
	$cat_ID   = (int) $cat_ID;
	$category = get_term( $cat_ID );

	if ( is_gc_error( $category ) ) {
		return $category;
	}

	return ( $category ) ? $category->name : '';
}