bp_members_prefetch_member_type( BP_User_Query $bp_user_query )
Pre-fetch profile type data when initializing a Members loop.
Description
Parameters
- $bp_user_query
-
(Required) BP_User_Query object.
Source
File: bp-members/bp-members-cache.php
function bp_members_prefetch_member_type( BP_User_Query $bp_user_query ) { $uncached_member_ids = bp_get_non_cached_ids( $bp_user_query->user_ids, 'bp_member_member_type' ); $member_types = bp_get_object_terms( $uncached_member_ids, bp_get_member_type_tax_name(), array( 'fields' => 'all_with_object_id', ) ); // Rekey by user ID. $keyed_member_types = array(); foreach ( $member_types as $member_type ) { if ( ! isset( $keyed_member_types[ $member_type->object_id ] ) ) { $keyed_member_types[ $member_type->object_id ] = array(); } $keyed_member_types[ $member_type->object_id ][] = $member_type->name; } $cached_member_ids = array(); foreach ( $keyed_member_types as $user_id => $user_member_types ) { wp_cache_set( $user_id, $user_member_types, 'bp_member_member_type' ); $cached_member_ids[] = $user_id; } // Cache an empty value for users with no type. foreach ( array_diff( $uncached_member_ids, $cached_member_ids ) as $no_type_id ) { wp_cache_set( $no_type_id, '', 'bp_member_member_type' ); } }
Changelog
Version | Description |
---|---|
BuddyPress 2.2.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.