WordPress update_user_meta() Function [Tutorial]


The update_user_meta() function in WordPress is designed to modify the metadata of a user stored in the WordPress database. It is particularly handy for adjusting user-specific details like custom fields, preferences, or any other supplementary data linked to a user.

Using the update_user_meta() function, developers have a straightforward method to alter and refresh user metadata without the need to directly interact with the WordPress database. This feature offers a safe and efficient approach to handling user-specific information within WordPress.

The update_user_meta() Function

Let’s take a look at the update_user_meta() function:


update_user_meta(int $user_id, string $meta_key, mixed $meta_value, mixed $prev_value = '')

Let’s take a look at the function parameters:

  1. $user_id (int): The ID of the user whose metadata will be updated.
  2. $meta_key (string): The key of the metadata being updated.
  3. $meta_value (mixed): The new value to be assigned to the metadata key.
  4. $prev_value (mixed): Optional. The previous value to check before updating. If specified, only updates if the existing value matches.


Int|true|false. Meta ID if the key didn’t exist, true on successful update, false on failure or if the value passed to the function is the same as the one that is already in the database.

Practical Applications

Now that we understand the syntax and parameters of update_user_meta(), let’s explore some practical applications.

1. Updating A Custom User Field

The update_user_meta() is commonly used to manage user profiles in WordPress. For instance, a plugin or custom code snippet might utilize this function to allow users to update their profile information such as bio, social media links, or profile pictures.


// Get current user ID
$user_id = get_current_user_id();

update_user_meta($user_id, 'user_bio', 'A passionate WordPress enthusiast');

2. Updating A List Of User Favorite Actors

The update_user_meta() function can also be used to update a list of favorite actors of the current user:


// Get current user ID
$user_id = get_current_user_id();

// List of actors
$actors = ['Tom Cruise', 'Brad Pitt', 'Ryan Gosling'];

update_user_meta($user_id, 'favorite_actors', $actors);

// Retreive a list of actors
$favorite_actors = get_user_meta($user_id, 'favorie_actors', true);
// result - ['Tom Cruise', 'Brad Pitt', 'Ryan Gosling']

3. Update A List Of Meta Values

We can also use update_user_meta() function to multiple meta values at once in a loop:


// Get current user ID
$user_id = get_current_user_id();
$meta_values = [
    'favorite_color' => 'Blue',
    'favorite_sport' => 'Hockey'

foreach ($meta_values as $meta_key => $meta_value) {
    update_user_meta($user_id, $meta_key, $meta_value);

Similar Functions

  • get_user_meta( int $user_id, string $key = ”, bool $single = false ) – the get_user_meta function retrieves a meta value for a given user
  • add_user_meta( int $user_id, string $meta_key, mixed $meta_value, bool $unique = false ) – Add
  • delete_user_meta(int $user_id, string $meta_key, mixed $meta_value = ”) – Removes metadata matching criteria from a user.


The update_user_meta() gives developers a handy way to update custom meta data of WordPress users. Give it a try in your work.

About The Author

Andriy Haydash

Andriy Haydash

Andriy Haydash is a WordPress Expert who helps people build and launch successful WordPress membership and e-learning websites.

Note: Not all of the articles are written directly by me.
Affiliate Disclaimer: Some links in the post may be my affiliate links

The Ultimate Managed Hosting Platform

Before YOU Leave...
Join My Newsletter

Get practical tips & tricks on how to start, grow and market your course/membership site.