Codex tools: Log in
If the user does not exist, the function returns
An alias of get_user_by('id').
<?php get_userdata( $userid ); ?>
get_userdata() returns an object of the user's data that you can assign to a variable. After that, 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 level: ' . $user_info->user_level . "\n"; echo 'User ID: ' . $user_info->ID . "\n"; ?>
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-> user_firstname; $last_name = $user_info-> user_lastname; echo "$first_name $last_name logs into her WordPress site with the user name of $username."; ?>
<?php $user_info = get_userdata(1); echo $user_info-> user_lastname . ", " . $user_info-> user_firstname . "\n"; ?>
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 that after wp 3.2, the return value has changed, a WP_User object is returned instead of a dumb object. However, through the usage of magic methods, data fields (such as the meta key rich_editing), get_userdata(1)->rich_editing will map to get_userdata(1)->data->rich_editing, even though in a var_dump() or similar will not show these extra fields. Refer http://core.trac.wordpress.org/ticket/18551.
get_userdata() is located in