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)
- Create a global variable for use in all templates
- 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 sorting options dropdown when using WooCommerce product category shortcode
- Drop down+sort blog posts date added/most popular
- How to auto login user again after change user_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
- Authenticating to WordPress, using my own authentication two-factor system
- 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?
- Delete option value from array using update_option()
- 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
- Order posts randomly, not by date
- How to get a list of all possible values of a specific user meta key?
- Sort posts by custom fields value using dropdown menu
- How to Sort posts by Vote Count?
- Sort custom meta column by other meta value
- PHP Fatal error: Out of memory in WordPress [closed]
- 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?
- add_cap not working
- 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?
- Call to undefined function get_userdata() in plugin
- Change CSS based on is_user_logged_in
- How to show a users bio on a page
- “operation successful” message
- Defined WordPress Memory Limit to Unlimited
- php if username is role
- How to keep track of when a vote is cast?
- WordPress hit memory limit but not from the server
- Show current user posts only
- PHP Warning: include(): Unable to allocate memory for pool
- Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday
- Show site content based on user role
- How to tag the main tag? [closed]
- 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
- Redirect to current user page upon link click
- Use of antispambot with $curauth->email
- Generate a QR code when creating a new WordPress user
- Change wordpress’ database data using ajax – how to get current user id?
- Sort column in Users admin Tab
- Allow a user or role to view drafts and previews, but not other admin privileges?
- Woocommerce display orders with products from specific categories to specific admins
- Admin Panel 404 Error after login
- How to block specific user id in custom login form?
- Get current user id in function php
- Display the list of user’s comments + the post title + date
- how can I call a function when time expire
- Call WP Rest-Api to GET /users/me returned NOTHING in console
- Uploading/integrating custom user registration page
- If user has clicked link add class and store using PHP/WordPress
- Store data from JavaScript object to custom table in user account
- Page template not working when logged out
- How to change the value of a variable using input field?
- How do I track which user clicked my button?
- Add another role to a user when they click a button?
- Query to show average # of months all accounts with specific role have been active
- wordpress more than one ajax request at the same time issue
- Editable Student file associated with basic User ID
- Adding users to another blog
- Changing WordPress author name in database
- Array sorting assistance
- Private messaging – Getting and displaying the avatar/url of a message recipient
- Updating custom user meta
- Page 2+ of taxonomy archives does not recognise sort-order from dropdown
- How to ‘remember’ a site member’s last visited page?
- How to connect database table to each registered wordpress user.
- Sort posts by title, sort array by largest number [duplicate]
- Get author meta of all writers
- Let users register weight each day and save it in DB
- WordPress – show all posts + ones with specific tag
- Display a list of users with avatar filterable with alphabets
- ISOTOPE – Missing/Invalid Arguement Get Terms
- WordPress Memory limit not increasing
- category & sub category order issues in wordpress
- Parse error: syntax error, unexpected ‘}’ in C:\wamp64\www\Proiect\aplicatie\user_check.php on line 18 [closed]
- Check if username doesn’t exists
- WP query with variables gives no result for specific user
- Difference between php memory limit and wp memory limit?
- How to lock users account until approvation
- Changing WP_MEMORY_LIMIT doesn’t affect actual memory limit
- How to create a User Role and give permission to only use Web Stories plugin?
- How to create custom user role without plugin?
- PHP Works only for logged in users: [closed]
- Custom Admin Menu Report for Specific User ID
- What is wrong with my sorting logic?
- How to add custom user role into wordpress