0

I have a dropdown where the user can select if he will checkout for him or for his customer. When registered, he gets two roles : Partner,[his_company].

So i want to display a dropdown with customers who have his role [his_company] but my code is not working.

<?php 

$billing_company =  get_user_meta( $current_user->ID, 'billing_company', 
true );


$args = array(
    'role' => $billing_company  // string|array,
);

wp_dropdown_users($args);
 ?>
0

1: $billing_company will return user billing_company whatever it is. 2: In $args you are supposed to put an array of user roles to fetch.

If you don't know user role then you can use global var global $current_user; and $user_roles = $current_user->roles; to get all current user roles, so it would be

$args = array(
   'role__in' => 'his_company';  // string|array,
);

Check if it works?

0

I found the solution. It was like this :

<?php 
$current_user=wp_get_current_user();


$args = array(
    'role' => $current_user->roles[1]  // string|array,
);

wp_dropdown_users($args);
 ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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