Get Users List by Role in WordPress


WordPress has six pre-defined roles

  1. Super Admin
  2. administrator
  3. editor
  4. author
  5. subscriber
  6. contributor


You can get all users of wordpress using following code. These code print all wordpress user’s list.

Display all subscribers list of wordpress

<?php
$args1 = array(
 'role' => 'subscriber',
 'orderby' => 'user_nicename',
 'order' => 'ASC'
);
 $subscribers = get_users($args1);
echo '<ul>';
 foreach ($subscribers as $user) {
 echo '<li>' . $user->display_name.'['.$user->user_email . ']</li>';
 }
echo '</ul>';
?>

Display all authors list of wordpress

<?php
$args2 = array(
 'role' => 'admin',
 'orderby' => 'user_nicename',
 'order' => 'ASC'
);
 $authors = get_users($args2);
echo '<ul>';
 foreach ($authors as $user) {
 echo '<li>' . $user->display_name.'['.$user->user_email . ']</li>';
 }
echo '</ul>';
?>

Please visit WordPress Codex to get more information about Role and Capabilities of wordpress users.

Advertisements

2 thoughts on “Get Users List by Role in WordPress”

  1. [ Smiles ] Wow, I have been on WordPress for a little over a year and I never knew that “Super Admin” existed!

    1. Yes, “Super Admin” is exists in WordPress. If you create a MultiSite in WordPress then you can control whole site administration (only if you a super admin).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s