Returns a WP_User object with the information pertaining to the user whose ID is passed to it. Properties de-referenced with "->" map directly to wp_users and wp_usermeta tables in the database (see Database Description).
If the user does not exist, the function returns
An alias of get_user_by('id').
<?php get_userdata( $userid ); ?>
The get_userdata() function returns an object of the user's data. You can echo various parts of the returned object or loop through the data to display it all.
Example displaying certain parts:
<?php $user_info = get_userdata(1); echo 'Username: ' . $user_info->user_login . "\n"; echo 'User roles: ' . implode(', ', $user_info->roles) . "\n"; echo 'User ID: ' . $user_info->ID . "\n"; ?>Results in:
You can also assign certain parts into individual variables for displaying later or in multiple places.
Example for extracting certain parts:
<?php $user_info = get_userdata(1); $username = $user_info->user_login; $first_name = $user_info->first_name; $last_name = $user_info->last_name; echo "$first_name $last_name logs into her WordPress site with the user name of $username."; ?>Results in:
<?php $user_info = get_userdata(1); echo $user_info->last_name . ", " . $user_info->first_name . "\n"; ?>Results in:
Here are some of the useful values in the wp_users and wp_usermeta tables you can access with this function for use in your theme or plugin:
Note: the WP_User object uses PHP 5 "magic" methods to provide some of its properties. For example:
$user_info->user_login is shorthand for $user_info->data->user_login, and
$user_info->rich_editing is shorthand for get_user_meta($user_info->ID, 'rich_editing', true).
get_userdata() is located in
Get User Functions: