Title: _prime_comment_caches
Published: December 9, 2015
Last modified: February 24, 2026

---

# _prime_comment_caches( int[] $comment_ids, bool $update_meta_cache = true )

## In this article

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

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

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

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

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

 * [update_comment_cache()](https://developer.wordpress.org/reference/functions/update_comment_cache/)

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

 `$comment_ids`int[]required

Array of comment IDs.

`$update_meta_cache`booloptional

Whether to update the meta cache.

Default:`true`

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

    ```php
    function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) {
    	global $wpdb;

    	$non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' );
    	if ( ! empty( $non_cached_ids ) ) {
    		$fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) );

    		update_comment_cache( $fresh_comments, false );
    	}

    	if ( $update_meta_cache ) {
    		wp_lazyload_comment_meta( $comment_ids );
    	}
    }
    ```

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

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

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

Queue comment meta for lazy-loading.

  | 
| [_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_comment_cache()](https://developer.wordpress.org/reference/functions/update_comment_cache/)`wp-includes/comment.php` |

Updates the comment cache of given comments.

  | 
| [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_comment_caches/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_prime_comment_caches/?output_format=md#)

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

Fetch descendants for located comments.

  | 
| [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_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.

  |

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

| Version | Description | 
| [6.3.0](https://developer.wordpress.org/reference/since/6.3.0/) | Use [wp_lazyload_comment_meta()](https://developer.wordpress.org/reference/functions/wp_lazyload_comment_meta/) for lazy-loading of comment meta. | 
| [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | This function is no longer marked as "private". | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.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_comment_caches%2F)
before being able to contribute a note or feedback.