I am trying to change this code in my Authors List page template

$all_users = get_users();
    $allowed_users = array();
    foreach ( $all_users as $user ):
        $wp_user = new WP_User($user->ID);
        if ( !in_array( 'subscriber', $wp_user->roles ) ):
            array_push($allowed_users, $user);

to show only authors instead of "everyone except subscribers". I tried this:

if ( in_array( 'author', $wp_user->roles ) ):

and it does not work.

How can I change this code to show only users defined as 'author'?


get_users has an argument that should let you select a particular role.

$all_users = get_users(array('role'=>'author'));

Should be all you need. $all_users should be only "Authors".

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.