Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ?

share|improve this question
    
This happened to me once, and I could never figure out why. The answer that I got was to do a fresh install. I could never do that, I just accepted the hidden user. –  westondeboer Aug 9 '12 at 22:36
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
There are many users in the database, not just 2. But you put me on the right track, after checking the user_meta fields, it appears that some fields (not all) are in double or triple. Maybe that is the cause. –  mike23 Sep 3 '12 at 14:10
    
I confirm that the duplicated users dissapeared once I cleaned up the user_meta table. The duplicated users where the ones who had duplicate user_meta entries. –  mike23 Sep 3 '12 at 14:44
    
Great news Mike! Strange that they would have been in twice.. –  Eric Holmes Sep 5 '12 at 13:17
add comment

maybe you can add a distinct filter on the get_users? http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_distinct

just spitballing..

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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