WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/update metadata

Description

Update metadata for the specified object. If no value already exists for the specified object ID and metadata key, the metadata will be added.

Calls 'update_{$meta_type}_meta' before updating metadata with meta_id of metadata entry to update, object ID, meta key, and meta value

Calls 'updated_{$meta_type}_meta' after updating metadata with meta_id of updated metadata entry, object ID, meta key, and meta value

Usage

<?php update_metadata $meta_type$object_id$meta_key$meta_value$prev_value ?>

Parameters

$meta_type
(string) (required) Type of object metadata is for (e.g., comment, post, or user)
Default: None
$object_id
(integer) (required) ID of the object metadata is for
Default: None
$meta_key
(string) (required) Metadata key (this should be raw as opposed to sanitized for database queries)
Default:
$meta_value
(string) (required) Metadata value (this should be raw as opposed to sanitized for database queries). Must be serializable if non-scalar.
Default:
$prev_value
(string) (optional) If specified, only update existing metadata entries with the specified value. Otherwise, update all entries.
Default: empty string (this should be raw as opposed to sanitized for database queries)

Return Values

(boolean) 
True on successful update, false on failure.

Change Log

Since: 2.9

Source File

update_metadata() is located in wp-includes/meta.php

Related

Metadata API: add_metadata(), get_metadata(), update_metadata(), delete_metadata()

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