0

Here's the code that i used:

function get_users(){
   $all_users = get_users();

   $arr=array();

   foreach ($all_users as $val) {
       $arr[]=$val->data->user_nicename;
   }

   $resp = array (
       'data'       => json_encode($arr)
   );
   wp_send_json($resp);
}

this code is working like this:

["john","mark","mena"]

I want the code to work like this:

[{value: "user_nicename", label: "display_name",icon: "user_avatar"}]
1
  • This isn't a question about WordPress so much as vanilla PHP, and as such might be considered off-topic for our site
    – bosco
    Commented Sep 27, 2017 at 2:03

1 Answer 1

0

Try this code

function get_users(){
    $all_users = get_users();
    $arr=array();

    foreach ($all_users as $val) {
       $arr[]=array( 'value'=> $val->data->user_nicename, 'label'=> $val->data->display_name, 'icon' => get_avatar_url($val->ID));
    }
    wp_send_json($arr);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.