Retrieves user info by user ID.
Parameters
$user_id
intrequired- User ID
Source
function get_userdata( $user_id ) {
return get_user_by( 'id', $user_id );
}
Changelog
Version | Description |
---|---|
0.71 | Introduced. |
Retrieves user info by user ID.
$user_id
intrequiredfunction get_userdata( $user_id ) {
return get_user_by( 'id', $user_id );
}
Version | Description |
---|---|
0.71 | Introduced. |
You must log in before being able to contribute a note or feedback.
Basic Usage
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:
Results in:
Username: admin
User roles: administrator
User ID: 1
You can also assign certain parts into individual variables for displaying later or in multiple places.
Example for extracting certain parts:
Results in:
Harriet Smith logs into her WordPress site with the user name of mrssmith.
Result : John, John@example.com
Accessing Usermeta Data
Results in:
Doe, John