update_post_thumbnail_cache

Update cache for thumbnails in the current loop.

Description

update_post_thumbnail_cache( (null) $wp_query = null ); 

Parameters (1)

0. $wp_query — Optional. (null) => null
A WP_Query instance. Defaults to the $wp_query global.

Usage

  1. if ( !function_exists( 'update_post_thumbnail_cache' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-thumbnail-template.php'; 
  3.  
  4. // Optional. A WP_Query instance. Defaults to the $wp_query global. 
  5. $wp_query = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = update_post_thumbnail_cache($wp_query); 
  9.  

Defined (1)

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

/wp-includes/post-thumbnail-template.php  
  1. function update_post_thumbnail_cache( $wp_query = null ) { 
  2. if ( ! $wp_query ) 
  3. $wp_query = $GLOBALS[wp_query]; 
  4.  
  5. if ( $wp_query->thumbnails_cached ) 
  6. return; 
  7.  
  8. $thumb_ids = array(); 
  9. foreach ( $wp_query->posts as $post ) { 
  10. if ( $id = get_post_thumbnail_id( $post->ID ) ) 
  11. $thumb_ids[] = $id; 
  12.  
  13. if ( ! empty ( $thumb_ids ) ) { 
  14. _prime_post_caches( $thumb_ids, false, true ); 
  15.  
  16. $wp_query->thumbnails_cached = true;