update_user_meta
Update user meta field based on user ID.
Description
(int|bool) update_user_meta( (int) $user_id, (string) $meta_key, (mixed) $meta_value, (string) $prev_value = '' );
Use the $prev_value
parameter to differentiate between meta fields with the same key and user ID.
If the meta field for the user does not exist, it will be added.
Returns (int|bool)
Meta ID if the key didn't exist, true on successful update, false on failure.
Parameters (4)
- 0. $user_id (int)
- The user id.
- 1. $meta_key (string)
- The meta key.
- 2. $meta_value (mixed)
- The meta value.
- 3. $prev_value — Optional. (string) =>
''
- Previous value to check before removing.
Usage
if ( !function_exists( 'update_user_meta' ) ) { require_once ABSPATH . WPINC . '/user.php'; } // The user id. $user_id = -1; // The meta key. $meta_key = ''; // The meta value. $meta_value = null; // Optional. Previous value to check before removing. $prev_value = ''; // NOTICE! Understand what this does before running. $result = update_user_meta($user_id, $meta_key, $meta_value, $prev_value);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/user.php
- function update_user_meta($user_id, $meta_key, $meta_value, $prev_value = '') {
- return update_metadata('user', $user_id, $meta_key, $meta_value, $prev_value);
- }