After a lot of trial and error I learnt that WP_User_Query takes an argument fields
which can be set to 'all_with_meta'
. This reduces number of queries to two for any number of users that are fetched in a single go and also provides benefits of caching. Usage would look like:
$user_query = new WP_User_Query( array('include' => $post_authors, 'fields' => 'all_with_meta') );
Related Posts:
- Getting all user metadata from user
- How to add custom query filters in WP_User_Query
- Searching user meta using WP_User_Query
- Query wp_usermeta alongside wp_users
- WP User Query get all authors with last name starting with specific letter
- How to properly use AND / OR in custom search
- Random users always showing same 8 users
- How to do WP_User_Query for Nested Array value Inside Nested Array field
- How to query 5 users in random who have published more than 10 posts
- WP_User_Query not searching numbers?
- Query Users by post count, last 30 days and display each users post count according to post type
- Get all user with both meta_value
- Wp_User_Query not sorting by meta key
- WP_User_Query with combined meta query – not working?
- SQL query equivalent to WP User Query
- Filter user list that meta_value is empty
- SQL User Query by Multiple Roles using PHP
- WP User Query fails when searching meta queries and search columns
- WP_User_Query unable to retreive all user at once
- Sort users by “birthday” using WP_User_Query
- Minimize database queries to user tables?
- Query users by capability – uninstall/deactivate callback
- How to display specific posts with WP_Query?
- Hide Administrators From User List except current user (administrator)
- WP_User_Query pulling ACF to loop
- WordPress search posts by author name with autocomplete
- pagination with numbers for WP_User_Query
- How to display user order by role
- Import wp users via one click demo option
- Meta_query on same meta key, with diffrenct values
- Dynamic User Id
- Get users that likes the post
- Passing args to WP_User_Query am I using meta correctly?
- Randomize Users
- Prevent author bio page from showing in search results
- WP User Query with Custom Fields and Search Results
- Get multiple users with meta value in one query and populate WP_User class
- Display if author page is author page of current user
- array of meta values using WP_User_Query
- Get user first name from custom endpoint
- Display the line breaks in user bio without using html
- WP_User_Query and user posts
- construct complex queries with WP User Query
- 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)
- query post by author gender
- WP_User_Query orderby meta_val_num
- Query to get last posts from authors of blog
- WP_User_Query not searching
- Replace wp_query with wp_user_query
- Query pages created by deleted users
- Counting instances of words in the results of a post query
- Query posts by post type, author and post meta
- SQL to join u3g_users & u3g_meta_value with repeating data
- Getting user data via ajax
- WP_User_Query Orderby Not Working
- Unusual high query of user meta data
- Set “editor” role to existing user
- How to query users by post count no less than 10
- using custom meta user data to run queries in WordPress
- Merge wp-query and get_users
- Get all wp_users sort by metakey
- Logging search queries for logged-in users
- Best way to query posts and order by relevancy to query
- List users by Year of Birth using a foreach loop to dynamically populate years and data
- Show subscriber id in loop
- Extend WP_User_Query or WP_User to return all custom fields?
- WP_Query within save_post doesn’t include the item that triggered the action?
- Search Functionality broken by the wp 4.2 update
- Sort users by custom user meta value
- How ‘secure’ are loops?
- Get users query makes the site loading time too big?
- Extend user search in the Wp backend area on the users.php page to allow for searching by email domain and role from the “users search” input box
- WordPress WP_User_Query ignores the `meta_query` when called from an Ajax function
- Single loop for wp_query and wp_user_query
- Filter wp_query to search post title in function
- Two queries on the same page with pagination
- Best approach to create Hot and Trending sections
- get complex results set according to category structure
- Setup of taxonomy term template pages
- Ignore post by meta value in the main query
- Display posts in 3 days chunk
- WP_Query’s “request” SQL Query
- is_search was called incorrectly
- Empty tax_query array returns an empty array
- Sorting By Custom Posts With Attachments
- Why isn’t my `meta_query` array functioning properly?
- Multisite pagination issue by multi query archive 404
- WordPress SQL Issue not returning correct reselts
- Hide elements outside loop based on query
- Combine 2 WP_queries into one (OR relation)
- One WP_Query that always shows 1 post from category X and 1 post from “not in category X”?
- get_posts query matches too many results
- Sort by custom field that is an array?
- Multi line of $wpdb->query just run 1 time and end the loop right after
- Sort posts on custom field AND after that sort on date?
- display the children of the post using the current page as the main parent
- In Product Category archives how to show Posts having same/similar prod_cat slug structure?
- Custom WP_query in Jnews theme returns thousands of posts
- wp_query, calculate with two dates when ‘key’ is text format