函数原型
get_category( int|object $category, string $output = OBJECT, string $filter = ‘raw’ ): object|array|WP_Error|null
函数描述
Retrieves category data given a category ID or category object.
是否弃用
未弃用
函数参数
-
$category
int|object
Required - Category ID or category row object.
-
$output
string
Optional - The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a WP_Term object, an associative array, or a numeric array, respectively.
Default:
OBJECT -
$filter
string
Optional - How to sanitize category fields. Default
'raw'.Default:
'raw'
函数返回值
object|array|WP_Error|null Category data in type defined by $output parameter.
WP_Error if $category is empty, null if it does not exist.
函数位置
File: wp-includes/category.php.
函数源码
function get_category( $category, $output = OBJECT, $filter = 'raw' ) {
$category = get_term( $category, 'category', $output, $filter );
if ( is_wp_error( $category ) ) {
return $category;
}
_make_cat_compat( $category );
return $category;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 1.5.1 | Introduced. |

