Taking @Kaperto’s advice, I did the following which works:
$user_query = new WP_User_Query( array(
'role__in' => ['role1','role2''],
'orderby' => 'meta_value_num',
'order' => 'ASC',
) );
$users = $user_query->get_results();
Related Posts:
- SQL query equivalent to WP User Query
- WP User Query get all authors with last name starting with specific letter
- Sort users by “birthday” using WP_User_Query
- Slow WP_Query for custom post type
- Hide Administrators From User List except current user (administrator)
- How to display user order by role
- Order by summing multiple values
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- SQL query injection with fifu image
- WP Query – grouping posts by same meta key, adding together values from another key
- Set “editor” role to existing user
- Get users query makes the site loading time too big?
- Which is faster wpdb & get_row or wp_query & ge_post_meta?
- How to pass orderby params to $wpdb->prepare()?
- how update data through ajax and jquery
- Debugging wp_query orderby for taxonomy
- Is it possible to query from external database? [duplicate]
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- Meta Query doesn’t works as espected
- Include post content of linked posts in search
- Prevent author bio page from showing in search results
- Make a SQL query with wpdb in WordPress
- Get multiple users with meta value in one query and populate WP_User class
- Getting additional columns from sql
- List of ways to access WordPress database?
- Reduce number of SQL queries inside WP_Query loop to fetch author data
- Display if author page is author page of current user
- how to get Nearby zipcode
- Getting rid of unwanted nonSQL syntax characters when debugging a query
- Get user first name from custom endpoint
- Query where ANDing slug values not working
- Update query for wp_posts and wp_postmeta
- Show menus to one admin username
- Slow Query On Search
- WP_Query: apply an SQL function to meta fileld value
- mysql query order by
- Storing an array of objects related to each user
- Create one-use post dynamically, add to main query, do not insert post (user profile view)
- Link Author URL’s based on a custom field
- WP_Query with page_ids in arguments without a result
- How to avoid filling up an array each time I run a WP_query?
- How to SQL query posts IDs by categories AND authors?
- Randomly select one of last 3 posts
- Query multiple meta key values for template
- Query to get last posts from authors of blog
- get_var is neither a string, integer, or array …?
- Passing a SQL query to the WP Query
- Query pages created by deleted users
- WP_Query() not working as expected
- Query posts by post type, author and post meta
- Random users always showing same 8 users
- Why last row deleted when refresh page
- Woocommerce Get Orders By Meta Value
- SQL to join u3g_users & u3g_meta_value with repeating data
- Any way to use FETCH_KEY_PAIR with $wpdb?
- What is the equivalent WP_Query of a SQL Query?
- INNER JOIN custom tables – SQL Query
- Meta query orderby meta_value_num sorting by role first
- use mysql variable in a $wpdb->query to reindex a column?
- One of two similar WP Query is very slow
- Fix wp_term_relationships slow query in get_posts
- Translating WP query into to SQL query
- WordPress Query optimaization for slow query
- Sorting query_posts() with a complex orderby filter
- Case insensitive ORDERBY in wpquery
- Pre_get_posts only show posts by administrator roles
- How to query 5 users in random who have published more than 10 posts
- How to query users by post count no less than 10
- Merge wp-query and get_users
- Filtering posts for unique titles, only the most recent
- Query postmeta based on meta_value, return array of post_id
- WP_Query: Query posts only if their access is restricted to logged user’s role
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- How to search CPTs in draft using get_page_by_title()
- Get all wp_users sort by metakey
- Order Posts By Custom Field That is an array of objects
- Logging search queries for logged-in users
- Multiple wpostmeta.meta_key
- Calculating efficiently on large amount of data generated by wp_query
- List users by Year of Birth using a foreach loop to dynamically populate years and data
- Slow query when selecting with large meta query or post__in
- SQL Query Search page
- What argument does my function need to echo get_results() query results
- Show subscriber id in loop
- Include post_status check within $wpdb query
- Find by post_meta, then sort by post_meta, then sort by date (wp_posts)
- Custom post order when using OR relation
- WP_Query always returning the last custom post
- WP Query to order posts by multiple meta fields
- How to connect database table to each registered wordpress user.
- Get a list of the last posts grouped by author and filtered by category
- How to count post meta key values for all posts in database
- Custom WP_Query with SQL directives for getting posts by authors and terms
- meta_query dates from an array
- How to return value from sql and display it
- orderby in WP_query doesn’t works
- WP_Query with several meta_query-statements and order by meta_value
- Displaying content to search engines but via navigation only for registered users.
- Query Users by post count, last 30 days and display each users post count according to post type
- Different sql queries count indicator on the main page [closed]