Authors List page – How to include only those with wp_user_level as Author

At my Authors template page, I want to show a complete list of Authors only (i.e. wp_user_level=2)
the code I used is like this:

$current = (intval(get_query_var('paged'))) ? intval(get_query_var('paged')) : 1;

$rows = $wpdb->get_results("SELECT ID, display_name from $wpdb->users 
WHERE ID NOT IN (1,2)
ORDER BY display_name");
$author_ids = $wpdb->get_results($query);
global $wp_rewrite;

for ($i=$start;$i < $end ;++$i ) {
   $row = $rows[$i];
 $curauth = get_userdata($row->ID);
 $user_link = get_author_posts_url($curauth->ID);
 $post_count = get_usernumposts($curauth->ID);
?>

But the problem is, this list is showing the “subscibers (wp_user_level=0)” as well. How can I exclude the users with wp_user_level=0

Related posts

Leave a Reply

1 comment

  1. The User Query Class

    There’s a class to query users. This makes a) more easy and b) more future proof as mostly the internals will change, but not the way you access it.

    $the_authors = new WP_User_Query( array( 
         'role' => 'author'
    ) );
    foreach ( $the_authors as $author )
    {
        // Show what we got:
        var_dump( $author );
        echo '<br />';
    
        // Access parts of the author/user object(!)
        // echo $author->first_name;
    }
    

    Role vs. User Level

    User level itself is deprecated since (I don’t know how many, but really many) versions. You shouldn’t use that. The idea behind it is that user levels are a hirachical way of organizing restrictions, while roles are not. In theory you can give a user more than one role to reflect the restrictions and possiblities she/he has in your system.