I have user display_name
and with this I want to get the id
of that user.
So, how can I get the user id?
I have user display_name
and with this I want to get the id
of that user.
So, how can I get the user id?
You must be logged in to post a comment.
You can use the following function:
This is the same code
get_user_by()
uses, but since that function only allowsID
,slug
,email
orlogin
we have to create a new function.Use
WP_User_Query
.Just answered one very similar to this: How we can get the author ID by its Name
I do not think that this has been mentioned, probably because it searches display_name as well as email address, URL, ID and username, this is more than required but worked well for my particular use case.
Completely untested, but I can’t see anything in the code why it wouldn’t work to use
get_users()
with a meta query:the wordpress user query by default doesn’t allow the display_name in search column even it’s added in , here is a solution http://manchumahara.com/2014/04/03/search-user-by-display-name-in-wordpress-sitewide/
Example:
The above query will not find for display_name
you need to use this filter