get user metaDescription
Retrieve a single meta field or all fields of user_meta data for the given user. Uses get_metadata(). This function replaces the deprecated get_usermeta() function.
Usage
<?php get_user_meta($user_id, $key, $single); ?>
Parameters
- $user_id
- (integer) (required) The ID of the user whose data should be retrieved.
- Default: None
- $key
- (string) (optional) The meta_key in the wp_usermeta table for the meta_value to be returned. If left empty, will return all user_meta fields for the given user.
- Default: (empty string)
- $single
- (boolean) (optional) If true return value of meta data field, if false return an array. This parameter has no effect if $key is left blank.
- Default: false
Return Values
- (mixed)
- Will be an Array if $key is not specified or if $single is false. Will be value of meta_value field if $single is true.
- NOTE
- If the meta value does not exist and $single is true the function will return an empty string. If $single is false an empty array is returned.
Examples
This example returns and then displays the last name for user id 9.
<?php $user_id = 9; $key = 'last_name'; $single = true; $user_last = get_user_meta( $user_id, $key, $single ); echo '<p>The '. $key . ' value for user id ' . $user_id . ' is: ' . $user_last . '</p>'; ?>