WordPress at a glance

get_user_by() WP 1.0

Retrieve user info by a given field

This is a pluggable function, and it can be replaced by a plugin. It means that this function is defined (works) only after all plugins are loaded (included), but before this moment this function has not defined. Therefore, you cannot call this and all functions depended on this function directly from a plugin code. They need to be called on plugins_loaded hook or later, for example on init hook.

Function replacement (override) — in a plugin you can create a function with the same name, then it replace this function.

Works based on: WP_User()
1 time — 0.0016251 sec (very slow) | 50000 times — 1.63 sec (fast) | PHP 7.4.8, WP 5.6

No Hooks.


WP_User|false. WP_User object on success, false on failure.


get_user_by( $field, $value );
$field(string) (required)
The field to retrieve the user with. id | ID | slug | email | login.
$value(int|string) (required)
A value for $field. A user ID, slug, email address, or login name.


Since 2.8.0 Introduced.
Since 4.4.0 Added 'ID' as an alias of 'id' for the $field parameter.

Code of get_user_by() WP 5.7.2

function get_user_by( $field, $value ) {
	$userdata = WP_User::get_data_by( $field, $value );

	if ( ! $userdata ) {
		return false;

	$user = new WP_User;
	$user->init( $userdata );

	return $user;

From tag: Users (_user)

More from category: Other

vladlu 100vlad.lu
Editors: Kama 100
No comments
    Log In