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'); ?> 

Return Values

(integer) 
  • true if new record is inserted or if existing record is replaced with a new value
  • false otherwise (including the case where the value has not changed)

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
This article is marked as in need of editing. You can help Codex by editing it.