_prime_comment_caches example

$comments_request = "SELECT $distinct {$wpdb->comments}.comment_ID FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";

            $key          = md5( $comments_request );
            $last_changed = wp_cache_get_last_changed( 'comment' ) . ':' . wp_cache_get_last_changed( 'posts' );

            $cache_key   = "comment_feed:$key:$last_changed";
            $comment_ids = wp_cache_get( $cache_key, 'comment-queries' );
            if ( false === $comment_ids ) {
                $comment_ids = $wpdb->get_col( $comments_request );
                wp_cache_add( $cache_key$comment_ids, 'comment-queries' );
            }
            _prime_comment_caches( $comment_ids );

            // Convert to WP_Comment.             /** @var WP_Comment[] */
            $this->comments      = array_map( 'get_comment', $comment_ids );
            $this->comment_count = count( $this->comments );

            $post_ids = array();

            foreach ( $this->comments as $comment ) {
                $post_ids[] = (int) $comment->comment_post_ID;
            }

            
$comment_ids = array_map( 'intval', $comment_ids );

        if ( $this->query_vars['update_comment_meta_cache'] ) {
            wp_lazyload_comment_meta( $comment_ids );
        }

        if ( 'ids' === $this->query_vars['fields'] ) {
            $this->comments = $comment_ids;
            return $this->comments;
        }

        _prime_comment_caches( $comment_ids, false );

        // Fetch full comment objects from the primed cache.         $_comments = array();
        foreach ( $comment_ids as $comment_id ) {
            $_comment = get_comment( $comment_id );
            if ( $_comment ) {
                $_comments[] = $_comment;
            }
        }

        // Prime comment post caches.
Home | Imprint | This part of the site doesn't use cookies.