функция since 1.5.0

update_post_caches()

Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.

Сигнатура

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

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.

Что будем искать? Например,Продвижение

Этот сайт использует куки-файлы. Оставаясь на сайте, Вы соглашаетесь на их использование. Для получения дополнительной информации, пожалуйста, ознакомьтесь с политикой в отношении персональных данных.