_prime_post_caches

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

Description

_prime_post_caches( (array) $ids, (constant) $update_term_cache = true, (bool) $update_meta_cache = true ); 

Parameters (3)

0. $ids (array)
The ids.
1. $update_term_cache — Optional. (constant) => true
Whether to update the term cache. Default true.
2. $update_meta_cache — Optional. (bool) => true
Whether to update the meta cache. Default true.

Usage

  1. if ( !function_exists( '_prime_post_caches' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // The ids. 
  5. $ids = array(); 
  6.  
  7. // Optional. Whether to update the term cache. Default true. 
  8. $update_term_cache = true; 
  9.  
  10. // Optional. Whether to update the meta cache. Default true. 
  11. $update_meta_cache = true; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = _prime_post_caches($ids, $update_term_cache, $update_meta_cache); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache = true ) { 
  2. global $wpdb; 
  3.  
  4. $non_cached_ids = _get_non_cached_ids( $ids, 'posts' ); 
  5. if ( !empty( $non_cached_ids ) ) { 
  6. $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ", ", $non_cached_ids ) ) ); 
  7.  
  8. update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );