get_category_parents()

最后更新于:2021-11-26 07:18:20

get_category_parents( int$category_id, bool$link=false, string$separator=’/’, bool$nicename=false, array$deprecated=array())

Retrieves category parents with separator.

参数

$category_id

(int) (Required) Category ID.

$link

(bool) (Optional) Whether to format with link.

Default value: false

$separator

(string) (Optional) How to separate categories.

Default value: ‘/’

$nicename

(bool) (Optional) Whether to use nice name for display.

Default value: false

$deprecated

(array) (Optional) Not used.

Default value: array()

响应

(string|GC_Error) A list of category parents on success, GC_Error on failure.

源文件

文件: gc-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 );
}