WP_User_Query and get_users cause 'Not unique table/alias' database error
-
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!
- The topic ‘WP_User_Query and get_users cause 'Not unique table/alias' database error’ is closed to new replies.