bp_core_get_users

Fetch an array of users based on the parameters passed.

Description

(array) bp_core_get_users( (string) $args = '' ); 

Since BuddyPress 1.7, bp_core_get_users() uses BP_User_Query. If you need backward compatibility with BP_Core_User::get_users(), filter the bp_use_legacy_user_query value, returning true.

Returns (array)

Parameters (1)

0. $args — Optional. (string) => ''
The args.

Options

    ;        


    Usage

    1. if ( !function_exists( 'bp_core_get_users' ) ) { 
    2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-functions.php'; 
    3.  
    4. // The args. 
    5. $args = ''; 
    6.  
    7. // NOTICE! Understand what this does before running. 
    8. $result = bp_core_get_users($args); 
    9.  

    Defined (1)

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

    /bp-members/bp-members-functions.php  
    1. function bp_core_get_users( $args = '' ) { 
    2.  
    3. // Parse the user query arguments. 
    4. $r = bp_parse_args( $args, array( 
    5. 'type' => 'active', // Active, newest, alphabetical, random or popular. 
    6. 'user_id' => false, // Pass a user_id to limit to only friend connections for this user. 
    7. 'exclude' => false, // Users to exclude from results. 
    8. 'search_terms' => false, // Limit to users that match these search terms. 
    9. 'meta_key' => false, // Limit to users who have this piece of usermeta. 
    10. 'meta_value' => false, // With meta_key, limit to users where usermeta matches this value. 
    11. 'member_type' => '',  
    12. 'member_type__in' => '',  
    13. 'member_type__not_in' => '',  
    14. 'include' => false, // Pass comma separated list of user_ids to limit to only these users. 
    15. 'per_page' => 20, // The number of results to return per page. 
    16. 'page' => 1, // The page to return if limiting per page. 
    17. 'populate_extras' => true, // Fetch the last active, where the user is a friend, total friend count, latest update. 
    18. 'count_total' => 'count_query' // What kind of total user count to do, if any. 'count_query', 'sql_calc_found_rows', or false. 
    19. ), 'core_get_users' ); 
    20.  
    21. // For legacy users. Use of BP_Core_User::get_users() is deprecated. 
    22. if ( apply_filters( 'bp_use_legacy_user_query', false, __FUNCTION__, $r ) ) { 
    23. $retval = BP_Core_User::get_users( 
    24. $r['type'],  
    25. $r['per_page'],  
    26. $r['page'],  
    27. $r['user_id'],  
    28. $r['include'],  
    29. $r['search_terms'],  
    30. $r['populate_extras'],  
    31. $r['exclude'],  
    32. $r['meta_key'],  
    33. $r['meta_value'] 
    34. ); 
    35.  
    36. // Default behavior as of BuddyPress 1.7.0. 
    37. } else { 
    38.  
    39. // Get users like we were asked to do... 
    40. $users = new BP_User_Query( $r ); 
    41.  
    42. // ...but reformat the results to match bp_core_get_users() behavior. 
    43. $retval = array( 
    44. 'users' => array_values( $users->results ),  
    45. 'total' => $users->total_users 
    46. ); 
    47.  
    48. /** 
    49. * Filters the results of the user query. 
    50. * @since 1.2.0 
    51. * @param array $retval Array of users for the current query. 
    52. * @param array $r Array of parsed query arguments. 
    53. */ 
    54. return apply_filters( 'bp_core_get_users', $retval, $r );