cache_users

Retrieve info for user lists to prevent multiple queries by get_userdata().

Description

cache_users( (array) $user_ids ); 

Parameters (1)

0. $user_ids (array)
User ID numbers list

Usage

  1. if ( !function_exists( 'cache_users' ) ) { 
  2. require_once ABSPATH . WPINC . '/pluggable.php'; 
  3.  
  4. // User ID numbers list 
  5. $user_ids = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = cache_users($user_ids); 
  9.  

Defined (1)

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

/wp-includes/pluggable.php  
  1. function cache_users( $user_ids ) { 
  2. global $wpdb; 
  3.  
  4. $clean = _get_non_cached_ids( $user_ids, 'users' ); 
  5.  
  6. if ( empty( $clean ) ) 
  7. return; 
  8.  
  9. $list = implode( ', ', $clean ); 
  10.  
  11. $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" ); 
  12.  
  13. $ids = array(); 
  14. foreach ( $users as $user ) { 
  15. update_user_caches( $user ); 
  16. $ids[] = $user->ID; 
  17. update_meta_cache( 'user', $ids );