I’m having a hard time figuring this one out.
I’m running a simple users query :
$args = array(
'role' => 'custom_role',
'orderby' => 'ID',
'order' => 'DESC',
'number' => 3
);
$users = get_users( $args );
And the resulting array has duplicate entries :
Array
(
[0] => stdClass Object
(
[ID] => 11433
[user_login] => peterpanpan
[user_pass] => $P$B1SJOYhvsDRBGLU4hpr4zsdffJdDD.Y0
[user_nicename] => peterpanpan
[user_email] => **********@gmail.com
[user_url] =>
[user_registered] => 2011-11-29 14:20:46
[user_activation_key] =>
[user_status] => 0
[display_name] => Peter Pan
)
[1] => stdClass Object
(
[ID] => 11433
[user_login] => peterpanpan
[user_pass] => $P$B1SJOYhvsDRBGLU4hpr4zsdffJdDD.Y0
[user_nicename] => peterpanpan
[user_email] => **********@gmail.com
[user_url] =>
[user_registered] => 2011-11-29 14:20:46
[user_activation_key] =>
[user_status] => 0
[display_name] => Peter Pan
)
[2] => stdClass Object
(
[ID] => 10663
[user_login] => dmartin
[user_pass] => $P$BLFk4yteiCQnVbyXMbMy4jOpBbytw3/
[user_nicename] => enfont
[user_email] => **********@yahoo.fr
[user_url] =>
[user_registered] => 2011-11-09 14:03:49
[user_activation_key] =>
[user_status] => 0
[display_name] => Deanmartin
)
)
In the example, $users[0] and $users[1] are exactly the same. In the database, there are no duplicates.
This started to happen recently, and the only thing that has been added was the W3 Total Cache plugin (but why would it cause such a behavior?). I tried deactivating it, but the duplicates remain.
Does anybody have a clue of what may be going on here ?
Seems like a silly question, but are there exactly 2 users in the database? Or are there more.
The only thing I can see happening is because you are setting to 3, it’s looping back through.
Another thing to try is checking the peterpanpan user, to see if he has the custom_role twice in his user_meta.
maybe you can add a distinct filter on the get_users?
http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_distinct
just spitballing..