You can use this function:
// get users with specified roles
function getUsersWithRole( $roles ) {
global $wpdb;
if ( ! is_array( $roles ) )
$roles = array_walk( explode( ",", $roles ), 'trim' );
$sql="
SELECT ID, display_name
FROM " . $wpdb->users . ' INNER JOIN ' . $wpdb->usermeta . '
ON ' . $wpdb->users . '.ID = ' . $wpdb->usermeta . '.user_id
WHERE ' . $wpdb->usermeta . '.meta_key = \'' . $wpdb->prefix . 'capabilities\'
AND (
';
$i = 1;
foreach ( $roles as $role ) {
$sql .= ' ' . $wpdb->usermeta . '.meta_value LIKE \'%"' . $role . '"%\' ';
if ( $i < count( $roles ) ) $sql .= ' OR ';
$i++;
}
$sql .= ' ) ';
$sql .= ' ORDER BY display_name ';
$userIDs = $wpdb->get_col( $sql );
return $userIDs;
}
Related Posts:
- Should I use wpdb prepare?
- what’s the meaning of the field wp_capabilities in table wp_usermeta
- Send user activation email when programmatically creating user
- Change default admin page for specific role(s)
- Add Custom User Capabilities Before or After the Custom User Role has Been Added?
- How to Change the Entire WordPress Admin panel Look and Feel?
- Getting wrong relationship value in $args in wp_Query?
- Does using set_transient() function can lead to MySQL problems?
- How to get data from WordPress $wpdb into React Gutenberg Blocks Frontend?
- How is the data stored in the database?
- How to Structure a New Role/Capability Scheme?
- How to add more than 1 user role to sub-menu pages
- How to allow Unfiltered HTML in a wordpress multisite install
- How can I free up the memory used by update_post_meta?
- Passing array of strings to a SQL statement in a WordPress plugin
- Activation hook not creating table
- Is the usage of ON DELETE CASCADE wrong or not allowed on wordpress?
- How to restrict plugin’s sub-menu pages to admin/subscribers?
- How to not let a user with a new role edit users that have administrator role?
- Execute plugin for specific user role(s) only
- How to edit mySQL wp_posts table from plugin php?
- Version upgrade: can my plugin filter the SQL statements issued during a database upgrade?
- $wpdb -> Batch insert from XML File?
- Hide plugin dashboard menu item for specific roles
- get_posts() not working when accessing with a custom user role
- WordPress database error for query INSERT INTO
- How to connect to AWS RDS external database (not for the core WordPress db)
- Limit role to one plugin [duplicate]
- Logout users upon login, based on caps/role?
- Set different custom menu items for different user roles
- Prevent third party plugin’s admin page access based on user type
- How to add user details to different tables immediately after user registration
- mysql_real_escape_string() vs. esc_sql() in WordPress
- wp_dropdown_roles() to replace option value = code
- How to get all queries’s results after they have executed?
- Hide custom post type by user roles
- $wpdb->prepare with LIKE and sprintf
- Alternative functions for mysql_free_result and mysql_ping in wordpress functions
- Check user’s role and store in variable
- Menu page with minimum capability as ‘Subscriber’ doesn’t allow ‘Admin’ to access it?
- Using AND and bracket grouping in SQL not working
- Two different wordpress sites – same server and IP address. Gaining Access to database 1 of 2
- How can I programmatically change a MySql variable (foreign_keys_check)?
- Auto-complete or auto-suggest from stored data in database
- What might be the reason of Couldn’t fetch mysqli_result on another domain?
- $wpdb->prepare is not working like mysql_real_escape_string
- Brainstorm – Slow Query from Plugin Need to Speed It Up
- Create an user on external database
- What could cause a WP Option to get truncated?
- How can I change my assigned user role in WordPress 3.5.1?
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- How to determine which capability to use?
- Foreign wp_users ID in custom plugin DB table?
- How to Get Last ID?
- Allow contributor user role to perform copy operation PHP
- Insert, update or remove data from database (usermeta)
- Enable a role named ‘backend_user’ to access my plugin pages
- WordPress how do I echo SUM from a column of a MySQL table by user id AND type_operation
- Why is that only the first row getting inserted into Mysql table when i import csv file on backend custom plugin?
- Add custom parameter for custom user role
- Error Connecting to Database WHEN Installing WordPress on XAMPP [Tried All the Usual Stuff] (Pics Included)
- Is it possible to replace MySQL with JSON files for WordPress
- Buddy Press restrict the capability to edit users
- WordPress doesn’t create table on plugin activation
- WordPress delete mysql rows with string
- How I can give access to my custom plugin for editor roles user?
- Organising and completing posts (mark as read and hide)
- pull data from wordpress database
- Remove all capabilities in separate method fails versus included in method
- Plugin MySQL SELECT custom data and filter on user meta
- Remove from a div by class name from post page if post author role is not administrator
- sql query not working in wp plugin
- $wpdb Mysql trigger problem
- Custom MySQL query to pull out Advanced Custom Fields?
- Adding admin for specific users
- What is more secure checking capabilities of user or checking role of user in WordPress plugin development
- New Users are saved with no role selected
- How to filter get_adjacent_post()?
- WordPress User Management Departmental Managers
- $wpdb how can i save my postmeta table before querying it
- Nothing happens on WordPress Update command
- Remove default wordpress roles
- Objective Best Practices for Plugin Development? [closed]
- add_menu_page() with different name for first submenu item
- Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?
- How to include PHP files in plugins the correct way
- How can I add an image upload field directly to a custom write panel?
- A tool to analyze rewrite rules? [closed]
- Difference Between Filter and Action Hooks?
- framework for plugin/theme options panel? [closed]
- Creating a table in the admin-style?
- How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
- Settings API with arrays example
- How to get the path to the current theme?
- How to make a plugin require another plugin?
- ajaxurl not defined on front end
- What process do you use for WordPress development? [closed]
- What’s the difference between term_id and term_taxonomy_id
- Why does WordPress use outdated jQuery v1.12.4?
- Post meta vs separate database tables