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 can use the following function:
function get_user_id_by_display_name( $display_name ) {
global $wpdb;
if ( ! $user = $wpdb->get_row( $wpdb->prepare(
"SELECT `ID` FROM $wpdb->users WHERE `display_name` = %s", $display_name
) ) )
return false;
return $user->ID;
}
This is the same code get_user_by()
uses, but since that function only allows ID
, slug
, email
or login
we have to create a new function.