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.

Parameters

$category_idintrequired
Category ID.
$linkbooloptional
Whether to format with link.

Default:false

$separatorstringoptional
How to separate categories. Default '/'.

Default:'/'

$nicenamebooloptional
Whether to use nice name for display.

Default:false

$deprecatedarrayoptional
Not used.

Default:array()

Return

string|WP_Error A list of category parents on success, WP_Error on failure.

Source

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 );
}

Changelog

VersionDescription
4.8.0The $visited parameter was deprecated and renamed to $deprecated.
1.2.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    Note that $nicename really means the slug. So if the $nicename parameter is set to true, the function will use the term slug for display, and using the default value of false will use the human readable display name of the term.

    May be confusing at first, as some of us may think human readable names are nicer than slugs.

You must log in before being able to contribute a note or feedback.