That’s the correct way to get what you need. Though I’m not sure why WordPress returns an array of roles since ( to my knowledge ) you can only have 1 role at a time. Roles being an array you can modify by just retrieving the role index 0:
$blogusers = get_users();
// Array of WP_User objects.
foreach ( $blogusers as $user ) {
echo '<span>' . esc_html( $user->user_email ) . '</span>';
echo '<span>' . esc_html( $user->roles[0] ) . '</span>';
}
Related Posts:
- How do I programmatically set default role for new users?
- How to programmatically add a user to a role?
- Order users by custom user meta
- List total number of users that are authors
- Can’t manage to make translate_user_role() work
- exclude roles from overview
- get approved users only ( ultimate member plugin )
- Query users which have same dynamically generated roles as the current user
- Menu page with list of users
- How to get a users list by who created them?
- Can someone help me out? Why isn’t this working?
- List users of specific role instead of removing them with specific role
- Getting a List of Currently Available Roles on a WordPress Site?
- Editor can create any new user except administrator
- How to get role of user
- What do unfiltered_html and unfiltered_upload actually filter?
- Check if user is admin by user ID
- Show admin bar only for some USERS roles
- How to update role capabilities
- create users to site with specific language
- How to loop through each user id?
- Ordering users of a specific role by last name
- How to stop a user from updating the post date
- how to add custom user capabilities using add_user_meta or something else?
- User roles – enable custom posts disable posts
- WordPress edit_user_profile_update update secondary role
- I need to assign a role to visitors/guests
- How to get the Role Name of the current user? (WordPress)
- How to get all users with Author role capabilities?
- set_role has no effect
- Add Role inherits?
- similar to Editor can create any new user except administrator
- How to check if a role has a specific capability
- Expire a user’s secondary role after X days from it being allocated
- Can a user with admin role get ‘Sorry, you are not allowed to move this item to the Trash’ error when trashing a post?
- Making shortcode of filtered number of comments by user role
- How to stop contributors editing post type but allowing them to edit a custom post type?
- Allow Block Editing By User Role
- How do I list in the backend all users that were assigned to a custom role?
- WordPress missing user roles on local dev machine. Live site works fine
- How to add local users to wordpress without email password?
- Programmatically allow a non-author to edit a post based custom meta field
- Register rest field for specific user
- Are User Levels Still Currently Used?
- Error: How to allow the “contributor” to upload media in wordpress
- Pending status by default for a specific role
- Getting a role based on a localized role name
- How do I restrict user access to plugins?
- Hiding posts by other users and non-logged in
- List all private pages user has access rights to read
- Admin User Role Unable to See Private Posts
- How can I allow an User to publish only 5 posts per month?
- Is possible to allow user to login with different role?
- Undo User Role Name Change
- add_role user capability not working
- Limit a user to have access to only specified pages?
- How can I promote a user to a network administrator?
- How do I let contributors edit their posts after being approved once?
- read_private_pages capability not working for new role
- Hide custom post type by user roles
- Hide comments and posts posted by other user
- Restrict custom post content to specific user
- Hiding custom theme functionality using capabilities
- How can I programattically hide all admin notices for everyone except admin users
- How to exclude subscriber from the list in wordpress
- how to make a custom field readonly or disabled by user role?
- Fix ‘Add Role’ Option not there in wordpress 5.2.2
- Create sub-administrator role that can do everything except use or see the code editor
- display user roles in comment form
- Mutliple users editing single document in wordspress
- Get Authors Role
- Custom user role still showing up after deletion, ideas?
- Retrieve user roles but exclude default roles
- Editor role can only create/edit/delete users who have one of two roles
- Disabled delete_others_posts if post is from admin
- Switch to user link shortcode
- How to hide Add new Term area for taxonomy terms for specific role (Client)
- Find count of WordPress users by role and search string for user name
- Saving user meta “member_id” based on user role
- Add Change role button for list of user in an event
- show the author’s role along with the name in the single.php
- Role and Capabilities: How do I allow user role to access theme options without enabling ‘manage_options’?
- fine-grained capabilities for user related capabilities
- How to Enable registration email for a custom user role?
- Custom User Role: Can Edit Own Page, Cannot Create New
- How can I add the ability for a user to add/edit administrators?
- How to sync user database with “user role editor” plugin enabled
- add user role selection to registration form [duplicate]
- Front end login and page restriction
- Get author meta of all writers
- Is there any way to give all users access to one blog in a multisite network without using a plugin?
- Assign specific editor with custom user meta “A” to all authors with custom user meta “A” and exclude all other author access
- Grant access to admin menu?
- i need to let a user to add a role from a frontend form
- I want this code to work only for Authors AND Contributors
- Disable Woocommerce checkout based on user role [closed]
- Remove_role not working, gives “Call to undefined method stdClass::remove_role()”
- Adding a new role with administrator’s capabilities
- How to create a specific role to manage users
- Role Scoper, don’t allow other users to see pending posts