cache_users() WordPress Function

The cache_users() function is used to retrieve a list of users from the user cache. This function is typically used to retrieve a list of users who are currently logged in or have recently interacted with the site.

cache_users( int[] $user_ids ) #

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


Parameters

$user_ids

(int[])(Required)User ID numbers list


Top ↑

Source

File: 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 );
	}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More