_prime_comment_caches

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

Description

_prime_comment_caches( (array) $comment_ids, (bool) $update_meta_cache = true ); 

Parameters (2)

0. $comment_ids (array)
Array of comment IDs.
1. $update_meta_cache — Optional. (bool) => true
Whether to update the meta cache. Default true.

Usage

  1. if ( !function_exists( '_prime_comment_caches' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // Array of comment IDs. 
  5. $comment_ids = array(); 
  6.  
  7. // Optional. Whether to update the meta cache. Default true. 
  8. $update_meta_cache = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = _prime_comment_caches($comment_ids, $update_meta_cache); 
  12.  

Defined (1)

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

/wp-includes/comment.php  
  1. function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) { 
  2. global $wpdb; 
  3.  
  4. $non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' ); 
  5. if ( !empty( $non_cached_ids ) ) { 
  6. $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", join( ", ", array_map( 'intval', $non_cached_ids ) ) ) ); 
  7.  
  8. update_comment_cache( $fresh_comments, $update_meta_cache );