函数原型
get_the_category_by_ID( int $cat_id ): string|WP_Error
函数描述
Retrieves category name based on category ID.
是否弃用
未弃用
函数参数
-
$cat_id
int
Required - Category ID.
函数返回值
string|WP_Error Category name on success, WP_Error on failure.
函数位置
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 : '';
}
源码链接
变更日志
| Version | Description |
|---|---|
| 0.71 | Introduced. |

