Skip to content

Instantly share code, notes, and snippets.

@LinzardMac
Created August 3, 2015 21:38
Show Gist options
  • Save LinzardMac/e9260af209e43141f695 to your computer and use it in GitHub Desktop.
Save LinzardMac/e9260af209e43141f695 to your computer and use it in GitHub Desktop.
function getUsers(){
header("Access-Control-Allow-Origin: *");
$term = $_GET['search'];
// var_dump($_GET);
$args = array(
'search' => '*'.esc_attr( $term ).'*',
'fields' => array('first_name', 'last_name', 'ID', 'display_name'),
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'first_name',
'value' => $term,
'compare' => 'LIKE'
),
array(
'key' => 'last_name',
'value' => $term,
'compare' => 'LIKE'
)
)
);
// The Query
$user_query = new WP_User_Query( $args );
$results = array();
// here you can see the whole user object being returned
wp_die(var_dump($user_query->results));
$results['results'] = $user_query->get_results();
$response = json_encode($results);
echo($response);
die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment