0

I'd like to get specific info about all users with a certain role, then display that info on a page.

So, I'd like to:

  1. Get all users with the role "Manager"
  2. Get each user's avatar, first name, last name, and bio text
  3. Display that info on a web page.

Note: This has nothing to do with user ID or the current logged in user.

How do I do this? Every option I see in the WP codex seems tied to current user or a user ID.

2

1 Answer 1

3

You could create a custom template page for this purpose and take advantage of the appropriate class provided by Wordpress itself: WP_User_Query

Eg:

// Create the WP_User_Query object
$wp_user_query = new WP_User_Query(array (
    'role' => 'Manager',
    'order' => 'ASC',
    'orderby' => 'display_name'
));

// Get the results
$managers = $wp_user_query->get_results();

// Looping managers
if (!empty($managers)) {
    echo '<ul>';
    foreach ($managers as $manager)
    {
        // get all the user's data
        $user_info = get_userdata($manager->ID);
        //printing basic infos
        echo '<li>';
        echo get_avatar( get_the_author_meta( $manager->ID ), 96 );
        echo $user_info->first_name;
        echo $user_info->last_name;
        echo '</li>';
    }
    echo '</ul>';
} else {
    echo 'No managers found';
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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