# get_post_ancestors()

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

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

## Сигнатура

```php
get_post_ancestors( int|WP_Post $post ): int[]
```

## Описание

Получает идентификаторы предков записи.

## Параметры

- `$post` `int|WP_Post` — обязательный. Идентификатор записи или объект записи.

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

`int[]`

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

Файл: `wp-includes/post.php:1159`

```php
function get_post_ancestors( $post ) {
	$post = get_post( $post );

	if ( ! $post || empty( $post->post_parent ) || $post->post_parent === $post->ID ) {
		return array();
	}

	$ancestors = array();

	$id          = $post->post_parent;
	$ancestors[] = $id;

	while ( $ancestor = get_post( $id ) ) {
		// Loop detection: If the ancestor has been seen before, break.
		if ( empty( $ancestor->post_parent ) || $ancestor->post_parent === $post->ID
			|| in_array( $ancestor->post_parent, $ancestors, true )
		) {
			break;
		}

		$id          = $ancestor->post_parent;
		$ancestors[] = $id;
	}

	return $ancestors;
}
```

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

- 2.5.0 — Introduced.

## Связанные

Использует: [`get_post`](https://chugunov.pro/api-wordpress/functions/get_post/).
Используется в: `WP_Posts_List_Table::single_row`, [`get_ancestors`](https://chugunov.pro/api-wordpress/functions/get_ancestors/), `WP_Post::__get`.

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