I using get_users to get users from my database.

I am using this code:

$args = array (
        'role'           => 'Colaborador',
        'role__not_in' =>[ 'subscriber', 'Administrator'],
        'orderby' => 'rand'


$users = get_users($args );

But in the output when use the foreach to print the data I need I found that are some user that are duplicate, appearing twice in the array.

How can i fix this?

1 Answer 1


I think it's arguments issue.

I recommend not to use role & role__not_in together rather either use only role OR use role__in & role__not_in combination. Also check your role param spelling. (see more on role)

2ndly orderby param rand is not valid according to codex (see here) so use proper param.

  • I remove role__not_in and check the role param spelling. But stil I get duplicate users in the query Nov 2, 2018 at 14:36
  • Ok, don't worry; try this $args = array('role'=>'contributor', 'orderby'=>'login'); and let me if not worked.
    – rony2k6
    Nov 2, 2018 at 17:17

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.