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

---

# _prime_post_caches( int[] $ids, bool $update_term_cache = true, bool $update_meta_cache = true )

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/_prime_post_caches/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/_prime_post_caches/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/_prime_post_caches/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/_prime_post_caches/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_prime_post_caches/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_prime_post_caches/?output_format=md#changelog)

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

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

## 󠀁[Description](https://developer.wordpress.org/reference/functions/_prime_post_caches/?output_format=md#description)󠁿

### 󠀁[See also](https://developer.wordpress.org/reference/functions/_prime_post_caches/?output_format=md#see-also)󠁿

 * [update_post_cache()](https://developer.wordpress.org/reference/functions/update_post_cache/)
 * [update_postmeta_cache()](https://developer.wordpress.org/reference/functions/update_postmeta_cache/)
 * [update_object_term_cache()](https://developer.wordpress.org/reference/functions/update_object_term_cache/)

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

 `$ids`int[]required

ID list.

`$update_term_cache`booloptional

Whether to update the term cache.

Default:`true`

`$update_meta_cache`booloptional

Whether to update the meta cache.

Default:`true`

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

    ```php
    function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache = true ) {
    	global $wpdb;

    	$non_cached_ids = _get_non_cached_ids( $ids, 'posts' );
    	if ( ! empty( $non_cached_ids ) ) {
    		$fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ) );

    		if ( $fresh_posts ) {
    			// Despite the name, update_post_cache() expects an array rather than a single post.
    			update_post_cache( $fresh_posts );
    		}
    	}

    	if ( $update_meta_cache ) {
    		update_postmeta_cache( $ids );
    	}

    	if ( $update_term_cache ) {
    		$post_types = array_map( 'get_post_type', $ids );
    		$post_types = array_unique( $post_types );
    		update_object_term_cache( $ids, $post_types );
    	}
    }
    ```

[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#L8271)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/post.php#L8271-L8293)

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

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

Retrieves IDs that are not already present in the cache.

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

Updates the cache for the given term object ID(s).

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

Updates metadata cache for a list of post IDs.

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

Updates posts in cache.

  | 
| [wpdb::get_results()](https://developer.wordpress.org/reference/classes/wpdb/get_results/)`wp-includes/class-wpdb.php` |

Retrieves an entire SQL result set from the database (i.e., many rows).

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/_prime_post_caches/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_prime_post_caches/?output_format=md#)

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

Updates post and term caches for all linked objects for a list of menu items.

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

Updates parent post caches for a list of post objects.

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

Filters specific tags in post content and modifies their markup.

  | 
| [WP_Widget_Media_Gallery::has_content()](https://developer.wordpress.org/reference/classes/wp_widget_media_gallery/has_content/)`wp-includes/widgets/class-wp-widget-media-gallery.php` |

Whether the widget has content to show.

  | 
| [WP_Comment_Query::get_comments()](https://developer.wordpress.org/reference/classes/wp_comment_query/get_comments/)`wp-includes/class-wp-comment-query.php` |

Get a list of comments matching the query vars.

  | 
| [WP_Posts_List_Table::_display_rows_hierarchical()](https://developer.wordpress.org/reference/classes/wp_posts_list_table/_display_rows_hierarchical/)`wp-admin/includes/class-wp-posts-list-table.php` |  | 
| [WP_Query::the_post()](https://developer.wordpress.org/reference/classes/wp_query/the_post/)`wp-includes/class-wp-query.php` |

Sets up the current post.

  | 
| [WP_Query::get_posts()](https://developer.wordpress.org/reference/classes/wp_query/get_posts/)`wp-includes/class-wp-query.php` |

Retrieves an array of posts based on query variables.

  | 
| [WP_Widget_Recent_Comments::widget()](https://developer.wordpress.org/reference/classes/wp_widget_recent_comments/widget/)`wp-includes/widgets/class-wp-widget-recent-comments.php` |

Outputs the content for the current Recent Comments widget instance.

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

Updates cache for thumbnails in the current loop.

  |

[Show 5 more](https://developer.wordpress.org/reference/functions/_prime_post_caches/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_prime_post_caches/?output_format=md#)

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

| Version | Description | 
| [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | This function is no longer marked as "private". | 
| [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. |

## User Contributed Notes

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