W3cubDocs

/WordPress

get_user_by( string $field, int|string $value )

Retrieve user info by a given field

Parameters

$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.

Return

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

Source

File: wp-includes/pluggable.php

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;
	}

Changelog

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

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_user_by