Codex

Function Reference/update usermeta

Contents

Description

This function updates the value of a specific meta_key pertaining to the user whose ID is passed via the userid parameter. It returns true if the update was successful and resulted in a new or changed record, and false otherwise.

Gotchas

  1. meta-key: Alphanumeric and underscore only. If the meta_key contains any characters besides [A-Za-z0-9_] (i.e. anything but letters, digits, and underscore), it is automatically stripped and inserted without the disallowed characters. For example, "opt-in" becomes "optin" – hyphen is not allowed in a meta_key.
  2. return value: unchanged record treated as error. If the new meta_value matches an existing value, the operation is considered an error and false is returned.

Usage

 <?php update_usermeta$userid$metakey$metavalue ); ?> 

Parameters

$userid
(integer) (required) The ID of the user whose data should be updated.
Default: None
$meta_key
(string) (required) The meta_key to be updated.
Default: None
$meta_value
(string) (required) The new desired value of the meta_key, which must be different from any existing value.
Default: None

Return Values

(bool) 
  • True on successful update.
  • False on update failure.

Change Log

Since: 2.0.0

Source File

update_usermeta() is located in wp-includes/user.php.

Related

get_usermeta(), update_usermeta(), delete_usermeta()

See also index of Function Reference and index of Template Tags.