I think you should use the default class for this job – WP_User_Query
.
The query have a lot of possibilities, also get the display name. WP_User_Query is a class that allows querying WordPress database tables _users
and _usermeta
.
Also it is helpful when you use a cache for the values. Also here I prefer the WordPress defaults WP_Cache
(Non-Persistent Cache) or transient API (Database-Driven Temporarily Persistent Cache).
The example below will demonstrate this with WP_Cache, you can also doing this with transients. The code will not work, is only write by scratch to illustrate.
function wpse_get_user_data( $args ) {
if ( ! $user_query = wp_cache_get( $args->ID, 'your_key' ) ) {
$user_query = array();
$user_query = new WP_User_Query( $args );
wp_cache_add( $args-ID, $user_query, 'your_key' );
}
return $user_query;
}
Related Posts:
- Get users that likes the post
- Loop 1 user randomly
- Allowed memory size of 268435456 bytes exhausted (tried to allocate 7146491840906359738 bytes)
- How to search display_name column when using WP_User_Query
- Create a global variable for use in all templates
- Add extra field to users
- How to order WP_User_Query results to match the order of an array of user IDs?
- Integrating WordPress to my website, while keeping my own authentication system
- Display user’s total comment count outside The Loop
- Display sorting options dropdown when using WooCommerce product category shortcode
- Changing user_nicename
- Drop down+sort blog posts date added/most popular
- How to auto login user again after change user_login
- Can i check if user is doing any ajax request?
- How do I create a WP user outside of WordPress and auto login?
- Network installation giving errors when viewing or adding a user
- Archive listing of posts by publish year (multiple years)
- Showing user ID on user main page from screen options
- Getting the Current User
- How do I hide specific user profile fields?
- How to get user by display_name with WP_User_Query
- Authenticating to WordPress, using my own authentication two-factor system
- How to track a users progress through pages by inserting data into WordPress Database?
- How to get a list of all users registered before a given date?
- WP_User_Query order by meta_key that is an array
- automated tests as a user?
- How can I default to all WordPress roles when parameter is not included in shortcode?
- there’s a way to include a minimal WP for check only the current user, its roles (caps?) and then release/free it?
- Sortable admin column for one meta key with three possible meta values
- Delete option value from array using update_option()
- get_users(…) only returns one user
- Memory errors with media upload, WordPress can’t use more than 96M (while there’s 512 available!)
- list posts and wrap them alphabetically A-Z
- List User order by ID in Descending order (Backend)
- Warning: Use of undefined constant HTTP_USER_AGENT – assumed ‘HTTP_USER_AGENT’ (this will throw an Error in a future version of PHP)
- Set WP_MAX_MEMORY_LIMIT higher than PHP.ini memory_limit
- Get all user meta by meta key instead of ID
- Order posts randomly, not by date
- How to get a list of all possible values of a specific user meta key?
- Nesting if statements to echo only one string based on what tag was filtered?
- Sort posts by custom fields value using dropdown menu
- User’s total comment count excluding comments on their own posts
- How to Sort posts by Vote Count?
- Sort query_posts for Parent Pages to menue order or the count?
- How to sort posts based on the value (number) of a post’s metadata?
- User management system similar to wordpress one?
- Show all posts by author
- Custom user login page by creating a plugin
- Sort custom meta column by other meta value
- PHP Fatal error: Out of memory in WordPress [closed]
- Sort the result of the main Query in shop page by a custom taxonomy
- Programmatic Login from 3rd Party site
- Add New User, extra fields which are required?
- user_profile_update_errors hook not executing
- Modify user profile data through scripting?
- Is it possible to increase php memory without directives in wp-config.php, .htaccess or php.ini?
- custom user role wordpress – grant guest access to edit.php without insert/update/delete
- add_cap not working
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Do not execute If User is login as Administrator or any Specific Role
- wordpress archive a user
- Best practice for show data to one specific user?
- Sort by page information by Ascending Numbers
- Call to undefined function get_userdata() in plugin
- get_users meta_query: REGEXP not working for matching new lines
- Change CSS based on is_user_logged_in
- How to show a users bio on a page
- “operation successful” message
- Normal PHP array for exclude section of WordPress query?
- Defined WordPress Memory Limit to Unlimited
- What is the difference in the WP memory limits?
- php if username is role
- How to keep track of when a vote is cast?
- How do you create two separate Register pages?
- WordPress hit memory limit but not from the server
- Is it possible to create new user from external form using REST API?
- Foreach loop inside an array_merge
- Show current user posts only
- change the default order of posts only for specific categories
- Change page password every day (predictable password ;) )
- PHP Warning: include(): Unable to allocate memory for pool
- show something only when user comes from specific page at remote host?
- Get the users that my following users are following
- Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday
- create front-end users post list by specific category
- How do I remove duplicate users from two merged WP_User_Query objects?
- Show site content based on user role
- How to tag the main tag? [closed]
- ‘pre_user_query’ interfering with user export
- Removing custom sort order from admin page listing
- php return username of currently viewed author profile
- How to list users like an archive page 10 users on page and have navigations
- How can I call a specific file (via php) by referencing the logged-in username?
- Redirect to current user page upon link click
- How to decrease the max file upload size without using php.ini or htaccess?
- Use of antispambot with $curauth->email
- Uses for function: wp_update_user
- Display additional user fields
- WordPress get last inserted user id
- Generate a QR code when creating a new WordPress user