I want to exclude Subscribers from a user list. My code is:
$users = $wpdb->get_results( "SELECT display_name FROM $wpdb->users ORDER BY display_name ASC" );
How can I change that so subscribers are excluded from the list?
I also looked at the get_users function in codex but it did not have an exclude by role parameter.Â
Edit: Or another way would be to get the results filtered by capability (one that subscribers doesn’t have).
How about
WP_User_Query
with the role__not_in argument.This new method should work. It looks at all the capability values to find “subscriber”, and hides it.
Try this query
You can use the
get_users()
function twice to exclude thesubscribers
.You can do something like this
$non_subscribers
contains the non subscribers.You can fetch the
display_name
by doing something like this