Using WordPress ‘get_userdatabylogin()’ PHP function

The get_userdatabylogin() WordPress PHP function retrieves user information by their login name.

Usage

$user_data = get_userdatabylogin( $user_login );

Parameters

  • $user_login (string) – Required. The user’s username to look up.

More information

See WordPress Developer Resources: get_userdatabylogin()

Examples

Get user data by login and display user’s display name

In this example, we’ll fetch the user data by their username and display their display name.

$user_login = "john_doe";
$user_data = get_userdatabylogin( $user_login );

echo "Display name: " . $user_data->display_name;

Get user data by login and display user’s email

In this example, we’ll fetch the user data by their username and display their email address.

$user_login = "john_doe";
$user_data = get_userdatabylogin( $user_login );

echo "Email: " . $user_data->user_email;

Get user data by login and display user’s ID

In this example, we’ll fetch the user data by their username and display their user ID.

$user_login = "john_doe";
$user_data = get_userdatabylogin( $user_login );

echo "User ID: " . $user_data->ID;

Get user data by login and display user’s website

In this example, we’ll fetch the user data by their username and display their website URL.

$user_login = "john_doe";
$user_data = get_userdatabylogin( $user_login );

echo "Website: " . $user_data->user_url;

Get user data by login and display user’s registration date

In this example, we’ll fetch the user data by their username and display their registration date.

$user_login = "john_doe";
$user_data = get_userdatabylogin( $user_login );

echo "Registration Date: " . $user_data->user_registered;