Uses
Uses | Description |
---|---|
wp-includes/meta.php: get_metadata() | Retrieves the value of a metadata field for the specified object type and ID. |
Retrieve user meta field for a user.
(int) (Required) User ID.
(string) (Optional) The meta key to retrieve. By default, returns data for all keys.
Default value: ''
(bool) (Optional) Whether to return a single value. This parameter has no effect if $key is not specified.
Default value: false
(mixed) An array if $single is false. The value of meta data field if $single is true. False for an invalid $user_id.
Please note that if the meta value exists but is empty, it will return an empty string (or array) as if the meta value didn’t exist. This might cause unexpected behaviors in your code when you empty the user meta, your code can try to use add_user_meta instead of update_user_meta thinking the user does not have meta created yet.
File: wp-includes/user.php
function get_user_meta( $user_id, $key = '', $single = false ) { return get_metadata( 'user', $user_id, $key, $single ); }
Version | Description |
---|---|
3.0.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_user_meta