Title: get_user_meta
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_user_meta( int $user_id, string $key, bool $single = false ): mixed

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#wp--skip-link--target)

Retrieves user meta field for a user.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#parameters)󠁿

 `$user_id`intrequired

User ID.

`$key`stringoptional

The meta key to retrieve. By default, returns data for all keys.

`$single`booloptional

Whether to return a single value.
 This parameter has no effect if `$key` is not
specified.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#return)󠁿

 mixed An array of values if `$single` is false.
 The value of meta data field if`
$single` is true. False for an invalid `$user_id` (non-numeric, zero, or negative
value). An empty array if a valid but non-existing user ID is passed and `$single`
is false. An empty string if a valid but non-existing user ID is passed and `$single`
is true. Note: Non-serialized values are returned as strings:

 * false values are returned as empty strings (`''`)
 * true values are returned as `'1'`
 * numbers (both integer and float) are returned as strings Arrays and objects retain
   their original type.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#more-information)󠁿

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.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#source)󠁿

    ```php
    function get_user_meta( $user_id, $key = '', $single = false ) {
    	return get_metadata( 'user', $user_id, $key, $single );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/user.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/user.php#L1281)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/user.php#L1281-L1283)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#related)󠁿

| Uses | Description | 
| [get_metadata()](https://developer.wordpress.org/reference/functions/get_metadata/)`wp-includes/meta.php` |

Retrieves the value of a metadata field for the specified object type and ID.

  |

| Used by | Description | 
| [WP_Application_Passwords::get_user_application_passwords()](https://developer.wordpress.org/reference/classes/wp_application_passwords/get_user_application_passwords/)`wp-includes/class-wp-application-passwords.php` |

Gets a user’s application passwords.

  | 
| [wp_initialize_site()](https://developer.wordpress.org/reference/functions/wp_initialize_site/)`wp-includes/ms-site.php` |

Runs the initialization routine for a given site.

  | 
| [wp_default_packages_inline_scripts()](https://developer.wordpress.org/reference/functions/wp_default_packages_inline_scripts/)`wp-includes/script-loader.php` |

Adds inline scripts required for the WordPress JavaScript packages.

  | 
| [the_block_editor_meta_boxes()](https://developer.wordpress.org/reference/functions/the_block_editor_meta_boxes/)`wp-admin/includes/post.php` |

Renders the meta boxes forms.

  | 
| [register_and_do_post_meta_boxes()](https://developer.wordpress.org/reference/functions/register_and_do_post_meta_boxes/)`wp-admin/includes/meta-boxes.php` |

Registers the default post meta boxes, and runs the `do_meta_boxes` actions.

  | 
| [wp_user_personal_data_exporter()](https://developer.wordpress.org/reference/functions/wp_user_personal_data_exporter/)`wp-includes/user.php` |

Finds and exports personal data associated with an email address from the user and user_meta table.

  | 
| [WP_User::get_caps_data()](https://developer.wordpress.org/reference/classes/wp_user/get_caps_data/)`wp-includes/class-wp-user.php` |

Gets the available user capabilities data.

  | 
| [WP_Widget_Text::render_control_template_scripts()](https://developer.wordpress.org/reference/classes/wp_widget_text/render_control_template_scripts/)`wp-includes/widgets/class-wp-widget-text.php` |

Renders form template scripts.

  | 
| [WP_Screen::render_meta_boxes_preferences()](https://developer.wordpress.org/reference/classes/wp_screen/render_meta_boxes_preferences/)`wp-admin/includes/class-wp-screen.php` |

Renders the meta boxes preferences.

  | 
| [WP_User_Meta_Session_Tokens::get_sessions()](https://developer.wordpress.org/reference/classes/wp_user_meta_session_tokens/get_sessions/)`wp-includes/class-wp-user-meta-session-tokens.php` |

Retrieves all sessions of the user.

  | 
| [choose_primary_blog()](https://developer.wordpress.org/reference/functions/choose_primary_blog/)`wp-admin/includes/ms.php` |

Handles the display of choosing a user’s primary site.

  | 
| [new_user_email_admin_notice()](https://developer.wordpress.org/reference/functions/new_user_email_admin_notice/)`wp-includes/user.php` |

Adds an admin notice alerting the user to check for confirmation request email after email address change.

  | 
| [WP_Internal_Pointers::enqueue_scripts()](https://developer.wordpress.org/reference/classes/wp_internal_pointers/enqueue_scripts/)`wp-admin/includes/class-wp-internal-pointers.php` |

Initializes the new feature pointers.

  | 
| [wp_ajax_save_user_color_scheme()](https://developer.wordpress.org/reference/functions/wp_ajax_save_user_color_scheme/)`wp-admin/includes/ajax-actions.php` |

Handles auto-saving the selected color scheme for a user’s own profile via AJAX.

  | 
| [wp_ajax_dismiss_wp_pointer()](https://developer.wordpress.org/reference/functions/wp_ajax_dismiss_wp_pointer/)`wp-admin/includes/ajax-actions.php` |

Handles dismissing a WordPress pointer via AJAX.

  | 
| [WP_User::__get()](https://developer.wordpress.org/reference/classes/wp_user/__get/)`wp-includes/class-wp-user.php` |

Magic method for accessing custom fields.

  | 
| [wp_update_user()](https://developer.wordpress.org/reference/functions/wp_update_user/)`wp-includes/user.php` |

Updates a user in the database.

  | 
| [get_blogs_of_user()](https://developer.wordpress.org/reference/functions/get_blogs_of_user/)`wp-includes/user.php` |

Gets the sites a user belongs to.

  | 
| [is_user_member_of_blog()](https://developer.wordpress.org/reference/functions/is_user_member_of_blog/)`wp-includes/user.php` |

Finds out whether a user is a member of a given blog.

  | 
| [get_active_blog_for_user()](https://developer.wordpress.org/reference/functions/get_active_blog_for_user/)`wp-includes/ms-functions.php` |

Gets one of a user’s active blogs.

  | 
| [add_user_to_blog()](https://developer.wordpress.org/reference/functions/add_user_to_blog/)`wp-includes/ms-functions.php` |

Adds a user to a blog, along with specifying the user’s role.

  | 
| [remove_user_from_blog()](https://developer.wordpress.org/reference/functions/remove_user_from_blog/)`wp-includes/ms-functions.php` |

Removes a user from a blog.

  |

[Show 17 more](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 6 content](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#comment-content-816)
 2.    [Giulio Daprela](https://profiles.wordpress.org/daprela/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_user_meta/#comment-816)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%23comment-816)
     Vote results for this note: 19[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%23comment-816)
 4.  If the key does not exist the function will return an empty string or an empty
     array depending on the value of the $single parameter
 5.   * It will also return boolean `false` if `! is_numeric( $user_id )` or `! absint(
        $user_id )`.
      * [thenbrent](https://profiles.wordpress.org/thenbrent/) [8 years ago](https://developer.wordpress.org/reference/functions/get_user_meta/#comment-2684)
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%3Freplytocom%3D816%23feedback-editor-816)
 7.   [Skip to note 7 content](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#comment-content-448)
 8.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_user_meta/#comment-448)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%23comment-448)
     Vote results for this note: 10[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%23comment-448)
 10. **Getting all meta data**
      This example demonstrates leaving the `$key` argument
     blank, in order to retrieve all meta data for the given user (in this example,`
     user_id = 9`):
 11.     ```php
         <?php
           $all_meta_for_user = get_user_meta( 9 );
           print_r( $all_meta_for_user );
         ?>
         ```
     
 12. Results:
 13. `Array ( [first_name] => Array ( [0] => Tom ) [last_name] => Array ( [0] => Auger)
     [
     nickname] => Array ( [0] => tomauger ) [description] => etc.... )
 14. Note: In order to access the data in this example you need to dereference the 
     array that is returned for each key, like so:
 15.     ```php
         $last_name = $all_meta_for_user['last_name'][0];
         ```
     
 16. To avoid this, you may want to run a simple `array_map()` on the results of `get_user_meta()`
     in order to take only the first index of each result (thus emulating what the `
     $single` argument does when `$key` is provided:
 17.     ```php
           $all_meta_for_user = array_map( function( $a ){ return $a[0]; }, get_user_meta( $user_id ) );
           print_r( $all_meta_for_user );
         ```
     
 18. Results:
 19. `Array ( [first_name] => Tom [last_name] => Auger [nickname] => tomauger [description]
     => etc.... )`
 20. Additionally, if you want to return ALL meta for a specific user and filter out
     empty values, you can run `array_filter()` on the results of the `array_map()`
     above:
 21.     ```php
         // Get all user meta data for $user_id
         $meta = get_user_meta( $user_id );
     
         // Filter out empty meta data
         $meta = array_filter( array_map( function( $a ) {
         	return $a[0];
         }, $meta ) );
         ```
     
 22.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%3Freplytocom%3D448%23feedback-editor-448)
 23.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#comment-content-447)
 24.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_user_meta/#comment-447)
 25. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%23comment-447)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%23comment-447)
 26. **This example returns and then displays the last name for user id 9.**
 27.     ```php
         <?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>'; 
         ?>
         ```
     
 28. Result:
 29. The last_name value for user id 9 is Franklin
 30.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%3Freplytocom%3D447%23feedback-editor-447)
 31.  [Skip to note 9 content](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#comment-content-4780)
 32.   [cartpauj](https://profiles.wordpress.org/cartpauj/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/get_user_meta/#comment-4780)
 33. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%23comment-4780)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%23comment-4780)
 34. Note: When doing `get_user_meta( $user_id );` without a meta key, the values are
     not unserialized automatically. You will need to `maybe_unserialize()` them.
 35.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%3Freplytocom%3D4780%23feedback-editor-4780)
 36.  [Skip to note 10 content](https://developer.wordpress.org/reference/functions/get_user_meta/?output_format=md#comment-content-1587)
 37.   [Goran87](https://profiles.wordpress.org/goran87/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/get_user_meta/#comment-1587)
 38. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%23comment-1587)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%23comment-1587)
 39. **To check if returned value is empty, ie does not exist, you could use something
     like:**
 40.     ```php
         global $current_user; 
     
         get_currentuserinfo();
     
         if ( $current_user ) {
         	$permission = get_user_meta( $current_user->ID, 'some_meta' , true );
     
         	if ( ! empty( $permission ) ) {
         		// do stuff
         	}
         }
         // works for both array and single values
         ```
     
 41.  * The function [get_currentuserinfo()](https://developer.wordpress.org/reference/functions/get_currentuserinfo/)
        is deprecated: [https://developer.wordpress.org/reference/functions/get_currentuserinfo/](https://developer.wordpress.org/reference/functions/get_currentuserinfo/)
      * [Jacob Hill](https://profiles.wordpress.org/tekfused/) [7 years ago](https://developer.wordpress.org/reference/functions/get_user_meta/#comment-3380)
 42.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F%3Freplytocom%3D1587%23feedback-editor-1587)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_meta%2F)
before being able to contribute a note or feedback.