get_user_meta

Retrieve user meta field for a user.

Description

get_user_meta( (int) $user_id, (string) $key = '', (constant) $single = false ); 

Parameters (3)

0. $user_id (int)
The user id.
1. $key — Optional. (string) => ''
The meta key to retrieve. By default, returns data for all keys.
2. $single — Optional. (constant) => false
Whether to return a single value.

Usage

  1. if ( !function_exists( 'get_user_meta' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4. // The user id. 
  5. $user_id = -1; 
  6.  
  7. // Optional. The meta key to retrieve. By default, returns data for all keys. 
  8. $key = ''; 
  9.  
  10. // Whether to return a single value. 
  11. $single = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = get_user_meta($user_id, $key, $single); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/user.php  
  1. function get_user_meta($user_id, $key = '', $single = false) { 
  2. return get_metadata('user', $user_id, $key, $single);