Logo Pupungbp.com

Need a WordPress expert help?

How to Display and Order Users on a Page

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.

Looking for an affordable WordPress solution?

We offer budget-friendly WordPress website development services to meet your needs. Prices start at $10.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.