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 
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

1 Answer 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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