WordPress at a glance

get_category_parents() WP 1.0

Retrieve category parents with separator.

Works based on: get_term_parents_list()

No Hooks.


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


get_category_parents( $category_id, $link, $separator, $nicename, $deprecated );
$category_id(int) (required)
Category ID.
Whether to format with link.
Default: false
How to separate categories.
Default: '/'
Whether to use nice name for display.
Default: false
Not used.


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

Code of get_category_parents() WP 5.7.2

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

From tag: Relations (of posts terms...)

More from category: Categories

No comments
    Log In