# update_post_caches()

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

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

## Сигнатура

```php
update_post_caches( WP_Post[] $posts, string $post_type = 'post', bool $update_term_cache = true, bool $update_meta_cache = true )
```

## Описание

Обновляет кэши записей, терминов и метаданных для списка объектов записей.

## Параметры

- `$posts` `WP_Post[]` — обязательный. Массив объектов записей (передаётся по ссылке).
- `$post_type` `string` — необязательный, по умолчанию `'post'`. Тип записи. Значение по умолчанию 'post'.
- `$update_term_cache` `bool` — необязательный, по умолчанию `true`. Обновлять ли кэш терминов.
- `$update_meta_cache` `bool` — необязательный, по умолчанию `true`. Обновлять ли кэш метаданных.

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

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

```php
function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) {
	// No point in doing all this work if we didn't match any posts.
	if ( ! $posts ) {
		return;
	}

	update_post_cache( $posts );

	$post_ids = array();
	foreach ( $posts as $post ) {
		$post_ids[] = $post->ID;
	}

	if ( ! $post_type ) {
		$post_type = 'any';
	}

	if ( $update_term_cache ) {
		if ( is_array( $post_type ) ) {
			$ptypes = $post_type;
		} elseif ( 'any' === $post_type ) {
			$ptypes = array();
			// Just use the post_types in the supplied posts.
			foreach ( $posts as $post ) {
				$ptypes[] = $post->post_type;
			}
			$ptypes = array_unique( $ptypes );
		} else {
			$ptypes = array( $post_type );
		}

		if ( ! empty( $ptypes ) ) {
			update_object_term_cache( $post_ids, $ptypes );
		}
	}

	if ( $update_meta_cache ) {
		update_postmeta_cache( $post_ids );
	}
}
```

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

- 1.5.0 — Introduced.

## Связанные

Использует: [`update_object_term_cache`](https://chugunov.pro/api-wordpress/functions/update_object_term_cache/), [`update_postmeta_cache`](https://chugunov.pro/api-wordpress/functions/update_postmeta_cache/), [`update_post_cache`](https://chugunov.pro/api-wordpress/functions/update_post_cache/).
Используется в: `WP_Query::get_posts`.

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