update_post_cache

The timeline below displays how wordpress function update_post_cache has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Updates posts in cache.
 *
 * @since 1.5.1
 *
 * @param WP_Post[] $posts Array of post objects (passed by reference).
 */
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');
}

WordPress Version: 5.3

/**
 * Updates posts in cache.
 *
 * @since 1.5.1
 *
 * @param WP_Post[] $posts Array of post objects (passed by reference).
 */
function update_post_cache(&$posts)
{
    if (!$posts) {
        return;
    }
    foreach ($posts as $post) {
        wp_cache_add($post->ID, $post, 'posts');
    }
}

WordPress Version: 4.9

/**
 * Updates posts in cache.
 *
 * @since 1.5.1
 *
 * @param array $posts Array of post objects (passed by reference).
 */
function update_post_cache(&$posts)
{
    if (!$posts) {
        return;
    }
    foreach ($posts as $post) {
        wp_cache_add($post->ID, $post, 'posts');
    }
}

WordPress Version: 4.0

/**
 * Updates posts in cache.
 *
 * @since 1.5.1
 *
 * @param array $posts Array of post objects, passed by reference.
 */
function update_post_cache(&$posts)
{
    if (!$posts) {
        return;
    }
    foreach ($posts as $post) {
        wp_cache_add($post->ID, $post, 'posts');
    }
}

WordPress Version: 3.9

/**
 * Updates posts in cache.
 *
 * @since 1.5.1
 *
 * @param array $posts Array of post objects
 */
function update_post_cache(&$posts)
{
    if (!$posts) {
        return;
    }
    foreach ($posts as $post) {
        wp_cache_add($post->ID, $post, 'posts');
    }
}

WordPress Version: 3.7

/**
 * Updates posts in cache.
 *
 * @package WordPress
 * @subpackage Cache
 * @since 1.5.1
 *
 * @param array $posts Array of post objects
 */
function update_post_cache(&$posts)
{
    if (!$posts) {
        return;
    }
    foreach ($posts as $post) {
        wp_cache_add($post->ID, $post, 'posts');
    }
}