update_comment_cache
Updates the comment cache of given comments.
Description
Will add the comments in $comments
to the cache. If comment ID already exists in the comment cache then it will not be updated. The comment is added to the cache using the comment group with the key using the ID of the comments.
Parameters (2)
- 0. $comments (array)
- Array of comment row objects
- 1. $update_meta_cache — Optional. (bool) =>
true
- Whether to update commentmeta cache. Default true.
Usage
if ( !function_exists( 'update_comment_cache' ) ) { require_once ABSPATH . WPINC . '/comment.php'; } // Array of comment row objects $comments = array(); // Whether to update commentmeta cache. Default true. $update_meta_cache = true; // NOTICE! Understand what this does before running. $result = update_comment_cache($comments, $update_meta_cache);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/comment.php
- function update_comment_cache( $comments, $update_meta_cache = true ) {
- foreach ( (array) $comments as $comment )
- wp_cache_add($comment->comment_ID, $comment, 'comment');
- if ( $update_meta_cache ) {
- // Avoid `wp_list_pluck()` in case `$comments` is passed by reference.
- $comment_ids = array();
- foreach ( $comments as $comment ) {
- $comment_ids[] = $comment->comment_ID;
- }
- update_meta_cache( 'comment', $comment_ids );
- }
- }