• Resolved jtyarks

    (@jtyarks)


    I was working on a site today that requires all users with the Contributor role be displayed.

    I first tried WP_User_Query

    $wp_user_search = new WP_User_Query( array( 'role' => 'contributor' ) );
    				$authors = $wp_user_search->get_results();
                    if (!empty($authors)) {
                        foreach ($authors as $author) {
                            $author_info = get_userdata($author->ID);
                               echo $curauth->user_url;
                      }
                    } else {
                        echo 'No users found.';
                    }

    and kept getting the ‘No users found.’ (there is one user currently). Then I tried get_users:

    $blogusers = get_users('role=contributor');
    				foreach ($blogusers as $user) {
    					echo '<p>' . $user->user_email . '</p>';
    				}

    When I still got nothing returned, I checked the error_log and saw this:

    [01-Jun-2012 16:47:06] WordPress database error Not unique table/alias: 'wp_usermeta' for query SELECT wp_users.* FROM wp_users INNER JOIN wp_usermeta ON (wp_users.ID = wp_usermeta.user_id) LEFT OUTER JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id AND wp_usermeta.meta_key = 'wp_capabilities' WHERE 1=1 AND ( (wp_usermeta.meta_key = 'wp_capabilities' AND CAST(wp_usermeta.meta_value AS CHAR) LIKE '%\"contributor\"%') ) AND (wp_usermeta.meta_value LIKE '%%') ORDER BY user_nicename ASC made by require, require_once, include, get_users, WP_User_Query->__construct, WP_User_Query->query

    If I use get_users without any parameters, they pull fine, but as soon as the parameter is added, something like that pops up.

    I don’t have any role changing plugins installed so I’m not quite sure what’s going on. Has anyone seen this kind of error before?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • When I use your second query in Twenty Ten, it works.

    First, try reinstalling WP by going to Dashboard->Updates and clicking ‘Reinstall Now’.

    If that does not help, try changing themes to see if it is a theme problem.

    If that doesn’t work, try deactivating all plugins.

    Thread Starter jtyarks

    (@jtyarks)

    Sorry, forgot to mention I did try your first two suggestions and it didn’t change anything…BUT I found out it is due to a plugin conflict – something about “Profile Builder Pro” is messing with the query.

    Not sure if these two can live in harmony, but I’ll be sure to post an update if I find a workaround.

    Thank you for your help, vtxyzzy!

    Any follow up on this issue?
    Got the same problem today, after i installed Profile Builder Pro, the function get_users( ‘role=whatever’ ) now returns an empty array. Trying to figure out where the conflict comes from.

    I had this issue and sent a fix through to barinagabriel, you shouldn’t experience this issue once using version 1.3.4, nor need to use his work-around.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WP_User_Query and get_users cause 'Not unique table/alias' database error’ is closed to new replies.