$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>array - How to avoid duplicate users when I am using get_users?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

array - How to avoid duplicate users when I am using get_users?

matteradmin10PV0评论

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?

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?

Share Improve this question asked Oct 30, 2018 at 20:07 Rivero FelipeRivero Felipe 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

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.

Post a comment

comment list (0)

  1. No comments so far