# get_boundary_post()

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

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

## Сигнатура

```php
get_boundary_post( bool $in_same_term = false, int[]|string $excluded_terms = '', bool $start = true, string $taxonomy = 'category' ): array|null
```

## Описание

Граница — это первая или последняя запись по дате публикации в рамках ограничений, заданных $in_same_term или $excluded_terms.

## Параметры

- `$in_same_term` `bool` — необязательный, по умолчанию `false`. Должна ли возвращаемая запись относиться к тому же термину таксономии.
- `$excluded_terms` `int[]|string` — необязательный, по умолчанию `''`. Массив или список ID исключаемых терминов, разделённых запятыми.
- `$start` `bool` — необязательный, по умолчанию `true`. Извлекать ли первую или последнюю запись.
- `$taxonomy` `string` — необязательный, по умолчанию `'category'`. Таксономия, если $in_same_term равно true. По умолчанию 'category'.

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

`array|null`

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

Файл: `wp-includes/link-template.php:2201`

```php
function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) {
	$post = get_post();

	if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) {
		return null;
	}

	$query_args = array(
		'posts_per_page'         => 1,
		'order'                  => $start ? 'ASC' : 'DESC',
		'update_post_term_cache' => false,
		'update_post_meta_cache' => false,
	);

	$term_array = array();

	if ( ! is_array( $excluded_terms ) ) {
		if ( ! empty( $excluded_terms ) ) {
			$excluded_terms = explode( ',', $excluded_terms );
		} else {
			$excluded_terms = array();
		}
	}

	if ( $in_same_term || ! empty( $excluded_terms ) ) {
		if ( $in_same_term ) {
			$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
		}

		if ( ! empty( $excluded_terms ) ) {
			$excluded_terms = array_map( 'intval', $excluded_terms );
			$excluded_terms = array_diff( $excluded_terms, $term_array );

			$inverse_terms = array();
			foreach ( $excluded_terms as $excluded_term ) {
				$inverse_terms[] = $excluded_term * -1;
			}
			$excluded_terms = $inverse_terms;
		}

		$query_args['tax_query'] = array(
			array(
				'taxonomy' => $taxonomy,
				'terms'    => array_merge( $term_array, $excluded_terms ),
			),
		);
	}

	return get_posts( $query_args );
}
```

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

- 2.8.0 — Introduced.

## Связанные

Использует: [`is_single`](https://chugunov.pro/api-wordpress/functions/is_single/), [`is_attachment`](https://chugunov.pro/api-wordpress/functions/is_attachment/), [`wp_get_object_terms`](https://chugunov.pro/api-wordpress/functions/wp_get_object_terms/), [`taxonomy_exists`](https://chugunov.pro/api-wordpress/functions/taxonomy_exists/), [`get_posts`](https://chugunov.pro/api-wordpress/functions/get_posts/), [`get_post`](https://chugunov.pro/api-wordpress/functions/get_post/).
Используется в: [`get_boundary_post_rel_link`](https://chugunov.pro/api-wordpress/functions/get_boundary_post_rel_link/).

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