WordPress开发者和主题制作者的搜索引擎



get_the_category_by_id ›

Since0.71
已弃用n/a
get_the_category_by_id ( $cat_ID )
参数:
  • (int) $cat_ID Category ID.
    Required: Yes
返回:
  • (string|WP_Error) Category name on success, WP_Error on failure.
定义在:
文档:

Retrieve category name based on category ID.



源码

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