How can I get a list of all users that are in WordPress by their role or capabilities?
For example:
- Display
all subscribers list
in WordPress. - Display
all authors list
in WordPress. - Display
all editors list
in WordPress.
There may be some different way to do that, but most proper way to do that is following.
<?php
$args = array(
'role' => 'Your desired role goes here.',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$users = get_users( $args );
echo '<ul>';
foreach ( $users as $user ) {
echo '<li>' . esc_html( $user->display_name ) . '[' . esc_html( $user->user_email ) . ']</li>';
}
echo '</ul>';
?>