函数原型
get_cat_name( int $cat_id ): string
函数描述
Retrieves the name of a category from its ID.
是否弃用
未弃用
函数参数
-
$cat_id
int
Required - Category ID.
函数返回值
string Category name, or an empty string if the category doesn’t exist.
函数位置
File: wp-includes/category.php.
函数源码
function get_cat_name( $cat_id ) {
$cat_id = (int) $cat_id;
$category = get_term( $cat_id, 'category' );
if ( ! $category || is_wp_error( $category ) ) {
return '';
}
return $category->name;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |

