• Hi all,

    I have a couple of custom user roles on the site I’m currently creating. I’d like to output the users of all these custom roles onto a page with their name and user role displayed. I’ve amended some code (found here Matt Varone) which allows me to output these details for one custom user type

    // prepare arguments
    $args  = array(
    // search only for Authors role
    'role' => 'photographer',
    // order results by display_name
    'orderby' => 'display_name',
    );
    // Create the WP_User_Query object
    $wp_user_query = new WP_User_Query($args);
    // Get the results
    $authors = $wp_user_query->get_results();
    // Check for results
    if (!empty($authors))
    {
        echo '<ul>';
        // loop trough each author
        foreach ($authors as $author)
        {
            // get all the user's data
            $author_info = get_userdata($author->ID);
            echo '<li>'.$author_info->first_name.' '.$author_info->last_name.'</li>';
        }
        echo '</ul>';
    } else {
        echo 'No authors found';
    }

    What I’ve been unable to do is do this for multiple user roles as the role will only accept the one string.

  • The topic ‘Display multiple users from multiple roles’ is closed to new replies.