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
- Group users by meta field, with name of meta field as group title
- 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
- Orderby meta _value that is saved as an array
- Complicated `orderby` based on text in custom field
- Transform user name before displaying
- Using a Query Loop Block with Variables (Custom Meta)
- How to remove “MY WORDPRESS”” Label
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- WP_Query by just the id?
- Meta_query compare operator explanation
- WP_Query with “post_title LIKE ‘something%'”?
- wp query to get child pages of current page
- How to get an array of post data from wp_query result?
- How to get post id of static front page?
- meta_query with meta values as serialize arrays
- How to only display posts whose meta_value field is not empty?
- Get post ids from WP_Query?
- Pagination when using wp_query?
- Exclude post ID from wp_query
- How to print the excuted sql right after its execution
- How to extend WP_Query to include custom table in query?
- How to store and receive variables in WP sessions?
- Should I use Pre Get Posts or WP_Query
- How can i retrieve default post per page value? from settings->reading. And total number of posts?
- Nested meta_query with multiple relation keys
- Is it necessary to use wp_reset_query() in a WP_Query call?