What is the best way to get all users who are above a certain role, like 'author'?

Is this the best way?

$user_args = array(
    'meta_query'    => array(
            'key' => 'wp_user_level',
            'value' => '2',
            'compare' => '>=',
            'type' => 'NUMERIC'

$users = get_users( $user_args );
  • wp_user_level is old school days thing. You might want to check this answer Fastforward to WordPress 4.4 - it will support the role__in attribute! ? – Sumit Mar 21 '16 at 5:39
  • I know I can pass an arbitrary list of roles, but that doesn't answer the question, how to get all users who are X role and above. – Justin Sternberg Mar 21 '16 at 18:52
  • Maybe I'm misunderstanding, but the idea of one role being 'above' another isn't quite the way I think about this. Generally, in that sense, I pick a capability that all the roles I would like to grab have, and then use a WP_User_Query with a meta_query. Key to look for in that meta query is prefix_capabilities – RichardTape Mar 21 '16 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.