I am currently working with the REST API and have the need to get_userdata() but instead of the user_id I have the username I also have their email if that helps.

Question: Is this possible within the core functionality of WordPress? If not is there a round about way to get user info via username and then get the user_id from that to do the get_userdata call?


1 Answer 1


get_userdata() function is an alias of get_user_by('ID') function. Use this code:

$username = 'your user name';
$user = get_user_by('login', $username);

It will return WP_User object on success, or false on failure. See Codex.

REST API: http://example.com/wp-json/wp/v2/users/<id>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.