Rolle
Member
Posted 10 months ago #
I know how to get user information from user id, but how to get user id from username? I tried something like $userid(user) but no joy. I need this because I'm trying to add gravatrs to wp-useronline -plugin which has username implementation but not user email. If this is not possible, then is it possible to get user email from username?
Thanks in advance.
Rolle
I think you want get_userdatabylogin():
$user = get_userdatabylogin('myusername');
echo $user->ID; // prints the id of the user
Rolle
Member
Posted 10 months ago #
Does not seem to work. Nothing prints out.
Rolle
Member
Posted 10 months ago #
Do var_dump($user); to see if any data is being returned from get_userdatabylogin. If myusername is the user name of a user, it will work, unless a plugin has redefined get_userdatabylogin so that it doens't work (unlikely).
Rolle
Member
Posted 10 months ago #
So how? Like this?:
var_dump($user)
$user = get_userdatabylogin('myusername');
echo $user->ID; // prints the id of the user
...which prints out NULL.
$user = get_userdatabylogin('admin');
var_dump($user);
echo $user->ID; // prints the id of the user
Rolle
Member
Posted 10 months ago #
Thanks. That worked fine for me.
I owe you one ;) Happy new year 2009.
Thank you thank you. I was looking for ever to find a means of extracting the userid from login name and your snippet worked a treat!