Title: update_post_cache
Published: April 25, 2014
Last modified: May 20, 2026

---

# update_post_cache( WP_Post[] $posts )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/update_post_cache/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/update_post_cache/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/update_post_cache/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/update_post_cache/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/update_post_cache/?output_format=md#wp--skip-link--target)

Updates posts in cache.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/update_post_cache/?output_format=md#parameters)󠁿

 `$posts`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)[]
required

Array of post objects (passed by reference).

## 󠀁[Source](https://developer.wordpress.org/reference/functions/update_post_cache/?output_format=md#source)󠁿

    ```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' );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/post.php#L7688)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/post.php#L7688-L7701)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/update_post_cache/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_cache_add_multiple()](https://developer.wordpress.org/reference/functions/wp_cache_add_multiple/)`wp-includes/cache.php` |

Adds multiple values to the cache in one call.

  | 
| [sanitize_post()](https://developer.wordpress.org/reference/functions/sanitize_post/)`wp-includes/post.php` |

Sanitizes every post field.

  |

| Used by | Description | 
| [get_children()](https://developer.wordpress.org/reference/functions/get_children/)`wp-includes/post.php` |

Retrieves all children of the post parent ID.

  | 
| [update_page_cache()](https://developer.wordpress.org/reference/functions/update_page_cache/)`wp-includes/deprecated.php` |

Alias of [update_post_cache()](https://developer.wordpress.org/reference/functions/update_post_cache/) .

  | 
| [update_post_caches()](https://developer.wordpress.org/reference/functions/update_post_caches/)`wp-includes/post.php` |

Updates post, term, and metadata caches for a list of post objects.

  | 
| [_prime_post_caches()](https://developer.wordpress.org/reference/functions/_prime_post_caches/)`wp-includes/post.php` |

Adds any posts from the given IDs to the cache that do not already exist in cache.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/update_post_cache/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.5.1](https://developer.wordpress.org/reference/since/1.5.1/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fupdate_post_cache%2F)
before being able to contribute a note or feedback.