Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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