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
if ( !function_exists( 'cache_users' ) ) { require_once ABSPATH . WPINC . '/pluggable.php'; } // User ID numbers list $user_ids = array(); // NOTICE! Understand what this does before running. $result = cache_users($user_ids);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/pluggable.php
- function cache_users( $user_ids ) {
- global $wpdb;
- $clean = _get_non_cached_ids( $user_ids, 'users' );
- if ( empty( $clean ) )
- return;
- $list = implode( ', ', $clean );
- $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" );
- $ids = array();
- foreach ( $users as $user ) {
- update_user_caches( $user );
- $ids[] = $user->ID;
- }
- update_meta_cache( 'user', $ids );
- }