+/**
+ * Update cache for thumbnails in the current loop
+ *
+ * @since 3.2
+ */
+function update_post_thumbnail_cache() {
+ global $wp_query;
+
+ if ( $wp_query->thumbnails_cached )
+ return;
+
+ $thumb_ids = array();
+ foreach ( $wp_query->posts as $post ) {
+ if ( $id = get_post_thumbnail_id( $post->ID ) )
+ $thumb_ids[] = $id;
+ }
+
+ if ( ! empty ( $thumb_ids ) ) {
+ get_posts( array(
+ 'update_post_term_cache' => false,
+ 'include' => $thumb_ids,
+ 'post_type' => 'attachment',
+ 'post_status' => 'inherit',
+ 'nopaging' => true
+ ) );
+ }
+
+ $wp_query->thumbnails_cached = true;
+}
+