get_category_parents() WordPress Function

The get_category_parents() function is a built-in WordPress function. It is used to display the parent categories of a given category. This function can be used in a theme template file or in a plugin file.

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

Retrieves category parents with separator.


Parameters

$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()


Top ↑

Return

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


Top ↑

Source

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


Top ↑

Changelog

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

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.