Created
September 7, 2012 21:16
-
-
Save eddiemoya/3669722 to your computer and use it in GitHub Desktop.
Get users by role with taxonomy sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT DISTINCT | |
u.ID, | |
u.user_login, | |
u.user_nicename, | |
u.user_email, | |
u.display_name, | |
m2.meta_value as role, | |
GROUP_CONCAT(DISTINCT m.meta_value) AS terms | |
FROM wp_users as u | |
LEFT JOIN wp_usermeta AS m | |
ON u.ID = m.user_id | |
AND m.meta_key = "um-taxonomy-category" | |
JOIN wp_usermeta AS m2 | |
ON u.ID = m2.user_id | |
AND m2.meta_key = 'wp_capabilities' | |
AND m2.meta_value REGEXP 'expert|author|editor|administrator' | |
GROUP BY u.ID | |
ORDER BY m.meta_key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To filter users by a specific term or set of terms, add the follwing immediately below line #12:
1, 2, 3 being the term_id's for the terms to filter by.