# get_term_parents_list()

URL: https://chugunov.pro/api-wordpress/functions/get_term_parents_list/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 4.8.0.

## Сигнатура

```php
get_term_parents_list( int $term_id, string $taxonomy, string|array $args = array() ): string|WP_Error
```

## Описание

Получает родительские термины с разделителем.

## Параметры

- `$term_id` `int` — обязательный. ID термина.
- `$taxonomy` `string` — обязательный. Имя таксономии.
- `$args` `string|array` — необязательный, по умолчанию `array()`. Массив необязательных аргументов.
  
  format stringИспользовать для отображения имена терминов или слаги. Принимает 'name' или 'slug'.
  
  Значение по умолчанию 'name'.
  
  separator stringРазделитель между терминами. Значение по умолчанию '/'.
  
  link boolНужно ли оформлять как ссылку. Значение по умолчанию true.
  
  inclusive boolВключать сам термин, для которого получаются родители. Значение по умолчанию true.

## Возвращаемое значение

`string|WP_Error` — WP_Error

## Исходный код

Файл: `wp-includes/category-template.php:1398`

```php
function get_term_parents_list( $term_id, $taxonomy, $args = array() ) {
	$list = '';
	$term = get_term( $term_id, $taxonomy );

	if ( is_wp_error( $term ) ) {
		return $term;
	}

	if ( ! $term ) {
		return $list;
	}

	$term_id = $term->term_id;

	$defaults = array(
		'format'    => 'name',
		'separator' => '/',
		'link'      => true,
		'inclusive' => true,
	);

	$args = wp_parse_args( $args, $defaults );

	foreach ( array( 'link', 'inclusive' ) as $bool ) {
		$args[ $bool ] = wp_validate_boolean( $args[ $bool ] );
	}

	$parents = get_ancestors( $term_id, $taxonomy, 'taxonomy' );

	if ( $args['inclusive'] ) {
		array_unshift( $parents, $term_id );
	}

	foreach ( array_reverse( $parents ) as $term_id ) {
		$parent = get_term( $term_id, $taxonomy );
		$name   = ( 'slug' === $args['format'] ) ? $parent->slug : $parent->name;

		if ( $args['link'] ) {
			$list .= '<a href="' . esc_url( get_term_link( $parent->term_id, $taxonomy ) ) . '">' . $name . '</a>' . $args['separator'];
		} else {
			$list .= $name . $args['separator'];
		}
	}

	return $list;
}
```

## История изменений

- 4.8.0 — Introduced.

## Связанные

Использует: [`wp_validate_boolean`](https://chugunov.pro/api-wordpress/functions/wp_validate_boolean/), [`get_ancestors`](https://chugunov.pro/api-wordpress/functions/get_ancestors/), [`get_term_link`](https://chugunov.pro/api-wordpress/functions/get_term_link/), [`esc_url`](https://chugunov.pro/api-wordpress/functions/esc_url/), [`wp_parse_args`](https://chugunov.pro/api-wordpress/functions/wp_parse_args/), [`get_term`](https://chugunov.pro/api-wordpress/functions/get_term/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/).
Используется в: [`get_category_parents`](https://chugunov.pro/api-wordpress/functions/get_category_parents/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/get_term_parents_list/
