函数原型
get_category_parents( int $category_id, bool $link = false, string $separator = ‘/’, bool $nicename = false, array $deprecated = array() ): string|WP_Error
函数描述
Retrieves category parents with separator.
是否弃用
未弃用
函数参数
-
$category_id
int
Required - Category ID.
-
$link
bool
Optional - Whether to format with link.
Default:
false -
$separator
string
Optional - How to separate categories. Default
'/'.Default:
'/' -
$nicename
bool
Optional - Whether to use nice name for display.
Default:
false -
$deprecated
array
Optional - Not used.
Default:
array()
函数返回值
string|WP_Error A list of category parents on success, WP_Error on failure.
函数位置
File: wp-includes/category-template.php.
函数源码
function get_category_parents( $category_id, $link = false, $separator = '/', $nicename = false, $deprecated = array() ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '4.8.0' );
}
$format = $nicename ? 'slug' : 'name';
$args = array(
'separator' => $separator,
'link' => $link,
'format' => $format,
);
return get_term_parents_list( $category_id, 'category', $args );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 4.8.0 | The $visited parameter was deprecated and renamed to $deprecated. |
| 1.2.0 | Introduced. |

