The get_usermeta() WordPress PHP function retrieves user metadata.
Usage
get_usermeta($user_id, $meta_key = '');
Example:
Input:
echo get_usermeta(1, 'user_website');
Output:
https://example.com
Parameters
$user_id
(int) – Required. The user ID.$meta_key
(string) – Optional. The metadata key. Default: ” (empty string)
More information
See WordPress Developer Resources: get_usermeta
Examples
Retrieve user’s website URL
Retrieve and display the website URL of a user with user ID 1.
$user_website = get_usermeta(1, 'user_website'); echo $user_website;
Get user’s first name and last name
Retrieve the first name and last name of a user with user ID 2.
$first_name = get_usermeta(2, 'first_name'); $last_name = get_usermeta(2, 'last_name'); echo $first_name . ' ' . $last_name;
Get user’s social media profiles
Retrieve the Twitter and Facebook profile URLs of a user with user ID 3.
$twitter = get_usermeta(3, 'twitter_profile'); $facebook = get_usermeta(3, 'facebook_profile'); echo "Twitter: $twitter <br> Facebook: $facebook";
Display user’s bio
Retrieve and display the bio of a user with user ID 4.
$user_bio = get_usermeta(4, 'user_bio'); echo $user_bio;
Get user’s custom field value
Retrieve the value of a custom field ‘user_custom_field’ for a user with user ID 5.
$custom_field_value = get_usermeta(5, 'user_custom_field'); echo $custom_field_value;