Last Updated: June 27, 2020 | Reading Time: < 1 minute
If you have registered users on certain role, to list them on a single page, you can use WP_User_Query
Here’s the basic loop:
$user_query = new WP_User_Query( $args );
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
echo $user->display_name;
}
} else {
echo 'No users found.';
}
You can list and order the result by adding array value, in below example I would like to order user by last name, the $arg array value should like:
$args = array(
'orderby' => 'meta_value',
'order' => 'DESC',
'meta_key' => 'last_name',
'role' => 'subscriber'
);
That’s it let me know if you have any questions.