Skip to content
Advertisement

Filter results by user role

I have a query that returns the total number of users per a specific meta value (gender), considering only users that are not blocked (user_blocked_access):

I have to return only the results for a specific user role:

But don’t know where I should adds this part of code.

Advertisement

Answer

You can add an additional JOIN:

Note: This assumes that there is only one wp_capabilities per user. If there are multiples, then EXISTS is safer:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement