I gave it a test run. First, I added a custom capability to a specific user, using following code
$user = new WP_User( $user_id );
$user->add_cap( 'team_member' );
Luckily, this user can be retrieved using below code, as you suggested
$args = array(
'role' => 'team_member'
);
get_users( $args );
Which implicitly work like below
$args = array (
'meta_query' => array(
array(
'key' => 'wp_capabilities',
'value' => '%team_member%',
'compare' => 'LIKE'
),
)
);
$wp_user_query = new WP_User_Query( $args );
Reference: WP_User_Query
Related Posts:
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- Editor can create any new user except administrator
- Remove Ability for Other Users to View Administrator in User List?
- Groups of capabilities: users with multiple roles?
- User-edit role setting distinct from wp_capabilities? [closed]
- How to let contributors to create a new revision(draft) editing their published posts
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- How to update user role without logout
- How to check user role without using current_user_can()
- Do not allow users to create new posts and pages
- \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
- How to enable the theme editor cap for an editor role?
- How to assign capabilities to user NOT to User Role
- How-to Delay The Capability To Publish Posts?
- Is there a simple way to manage capabilities per user?
- Get User Role by ID not working
- Are User Levels Still Currently Used?
- Remove Capabilities from WP admin for specific user role
- Add a role and give admin priviledges
- Where are $current_user->allcaps set?
- What’s the correct way to add capabilites to user roles?
- Can I Create a Second Admin Level User Role?
- Assigning multiple or additional capabilities to specific users or how to create additional roles like bbpress roles?
- how do I add role and capability after I create a new user
- How to make WordPress ‘editor’ role to list/view/add/edit users only with the role ‘author’?
- Find count of WordPress users by role and search string for user name
- fine-grained capabilities for user related capabilities
- Disabling user capability to edit_posts or delete_posts in the front-end
- Groups roles & capabilities
- Subscriber role – blank page
- current_user_can() returning true for capability when the user and role do not have the capability
- Show only users with the same role in Dashboard user list
- If the current user is an administrator or editor
- Getting a List of Currently Available Roles on a WordPress Site?
- How to allow an user role to create a new user under a role which lower than his level only?
- Find out if logged in user is not subscriber
- List users by last name in WP_User_Query
- What’s the difference between the capability remove_users and delete_users?
- Allowing users to edit only their page and nobody else’s
- alphabetically order role drop-down selection in dashboard
- Execute a function when admin changes the user role
- What the user_status column?
- Add Custom User Capabilities Before or After the Custom User Role has Been Added?
- Hide Admin Menu for Specific User ID who has administrator Role
- How to hide media uploads by other users in the Media menu?
- Show admin bar only for some USERS roles
- Grouping users under parent user
- Wp_User_Query not sorting by meta key
- WP_User_Query with combined meta query – not working?
- pre_user_query meta_query admin user list
- How to programmatically add a user to a role?
- Prevent user creating new users with specific roles
- How to assign an additional/extra/second user-role to multiple users (of a specific user-role)
- How to stop a user from updating the post date
- BuddyPress | Check if user is in current group [closed]
- Return ID of authors who have at least one post
- WordPress edit_user_profile_update update secondary role
- How do I properly format the user_role array?
- How to restrict specific post types from being read or added by specific user roles (eg. author)?
- How to customize wp_signon()
- Is it possible to get a user with just the password field?
- How to get the Role Name of the current user? (WordPress)
- Prevent Admin user to edit/see super admin from users list
- Redirect after login based on user role (custom login page)
- set_role has no effect
- WP_User->add_role producing unexpected results
- How can I check if the admin bar is visible to the current user?
- Can I create users that have access to *some* other users posts instead of all other users posts?
- Set default page for user account in admin
- How to use search_columns in WP_User_Query?
- User role permissions based on taxonomies
- Users roles, make a page belonging to multiple users
- Tagging users in WordPress
- Redirect after users complete profile form
- How do I list in the backend all users that were assigned to a custom role?
- How to query users who have empty first_name?
- WordPress User getting added with id of 0
- How to add local users to wordpress without email password?
- WP User Query fails when searching meta queries and search columns
- Hide everything on site for visitors except specific page IDs
- current user can edit user?
- the_author_meta(‘user_url’, $author->ID) not working properly. how can I solve this?
- add_cap not working with Shop Manager role
- Managing Users and Creating Groups [closed]
- Restricted registrations or removing the ability to edit your password/email
- How to disable a specific page for a specific user
- Error: How to allow the “contributor” to upload media in wordpress
- Roles for Custom Post Types
- Does an AJAX call on the Admin Side Automatically include the User Data/Capabilities?
- how to know when the user is in specific part of the website and when he leaves that part and display the data in the admin dashboard
- Updating wp_user_level on user update
- wordpress user roles are not working
- Displaying different in-page content to cliente/admin
- Fix permissions for users role
- User capability for editing their own comments
- What are some best practices for user exit strategy?
- Is there a way to identify a user in a custom REST API method? [duplicate]
- WP_User_Query – searching multiple fields
- Problem with automatic role change through cron job
- Allow Contributors to Upload Files