update_post_cache() WordPress Function

The update_post_cache() function is used to update the post cache. This function will take an array of post objects and update the post cache.

update_post_cache( WP_Post[] $posts ) #

Updates posts in cache.


Parameters

$posts

(WP_Post[])(Required)Array of post objects (passed by reference).


Top ↑

Source

File: wp-includes/post.php

function update_post_cache( &$posts ) {
	if ( ! $posts ) {
		return;
	}

	$data = array();
	foreach ( $posts as $post ) {
		if ( empty( $post->filter ) || 'raw' !== $post->filter ) {
			$post = sanitize_post( $post, 'raw' );
		}
		$data[ $post->ID ] = $post;
	}
	wp_cache_add_multiple( $data, 'posts' );
}


Top ↑

Changelog

Changelog
VersionDescription
1.5.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More