Created
May 15, 2020 03:52
-
-
Save ahmedmusawir/0330d06a66c13f472a1cb120669d1904 to your computer and use it in GitHub Desktop.
BUDDYPRESS - WP_USER_QUERY - GET USERS W/ ROLES & BP CUSTOM FIELDS - AJAX FUNCTION
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ATHLETE LOAD MORE WP FUNCITON FOR JQUERY AJAX | |
*/ | |
add_action('wp_ajax_nopriv_athlete_dynamic_location_ajax_function', 'athlete_dynamic_location_ajax_function'); | |
add_action('wp_ajax_athlete_dynamic_location_ajax_function', 'athlete_dynamic_location_ajax_function'); | |
function athlete_dynamic_location_ajax_function() { | |
// LOAD MORE UNIV POSTS | |
$item_count = 0; | |
$locations = array(); | |
$args = array( | |
'role' => 'athlete' | |
); | |
// The Query | |
$user_query = new WP_User_Query( $args ); | |
// User Loop | |
if ( ! empty( $user_query->get_results() ) ) { | |
foreach ( $user_query->get_results() as $user ) { | |
$user_id = $user->id; | |
// SPORTS & LOCATION | |
// $sport = xprofile_get_field_data( 49, $user_id, $multi_format = 'array' ); | |
$nationality = xprofile_get_field_data( 11, $user_id, $multi_format = 'array' ); | |
$item_count++; | |
array_push($locations, $nationality); | |
// echo '<li>'; | |
// echo $nationality; | |
// echo '</li>'; | |
// echo '<pre>'; | |
// print_r($user); | |
// echo '</pre>'; | |
} | |
} else { | |
echo 'No users found.'; | |
} | |
$unique_location_list = array_unique($locations); | |
echo $item_count; | |
echo '<pre>'; | |
print_r($locations); | |
echo 'UNIQUE LIST:'; | |
print_r($unique_location_list); | |
echo '</pre>'; | |
die(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment