Languages: English • 日本語 (Add your language)
Update user meta field based on user ID.
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.
<?php update_user_meta( $user_id, $meta_key, $meta_value, $prev_value ); ?>
Below is an example showing how to update a user's Website profile field
<?php $user_id = 1; $website = 'http://wordpress.org'; update_user_meta($user_id, 'user_url', $website); ?>
Below is an example showing how to check for errors:
$user_id = 1; $new_value = 'some new value'; // will return false if the previous value is the same as $new_value update_user_meta( $user_id, 'some_meta_key', $new_value ); // so check and make sure the stored value matches $new_value if ( get_user_meta($user_id, 'some_meta_key', true ) != $new_value ) wp_die('An error occurred'); ?>
Changes in behavior from the now deprecated update_usermeta:
Since: 3.0.0
update_user_meta() is located in wp-includes/user.php
.
add_user_meta(), delete_user_meta(), get_user_meta(), update_user_meta(), get_user_option(), delete_user_option(), update_user_option(),