Codex

Function Reference/get user meta

Contents

Description

Retrieve user meta field for a user, using 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) (required) The metakey value to be returned.
Default: None
$single
(boolean) (optional) If true return value of meta data field, if false return an array.
Default: false

Return Values

(mixed) 
Will be an array if $single is false or will be value of meta data 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>'; 
?>
The last_name value for user id 9 is Franklin


Notes

Filters

Change Log

Since: 3.0

Source File

get_user_meta() is located in wp-includes/user.php.

Related

add_user_meta(), delete_user_meta(), get_user_meta(), update_user_meta()

See also index of Function Reference and index of Template Tags.