get_category()

最后更新于:2021-11-26 07:02:27

get_category( int|object$category, string$output=OBJECT, string$filter=’raw’)

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 GC_Term object, an associative array, or a numeric array, respectively.

Default value: OBJECT

$filter

(string) (Optional) How to sanitize category fields.

Default value: ‘raw’

响应

(object|array|GC_Error|null) Category data in type defined by $output parameter. GC_Error if $category is empty, null if it does not exist.

源文件

文件: gc-includes/category.php

function get_category( $category, $output = OBJECT, $filter = 'raw' ) {
	$category = get_term( $category, 'category', $output, $filter );

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

	_make_cat_compat( $category );

	return $category;
}