WPDev.one
Core Function
View Source on Trac ↗

add_metadata()

add_metadata( mixed $meta_type, mixed $object_id, mixed $meta_key, mixed $meta_value, mixed $unique = false )

Adds metadata for the specified object.

Parameters 5 required

Name / Type Description
string

$meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', or any other object type with an associated meta table.

Required
$object_id
int

ID of the object metadata is for.

Required
$meta_key
string

Metadata key.

Required
mixed

$meta_value Metadata value. Arrays and objects are stored as serialized data and will be returned as the same type when retrieved. Other data types will be stored as strings in the database: - false is stored and retrieved as an empty string ('') - true is stored and retrieved as '1' - numbers (both integer and float) are stored and retrieved as strings Must be serializable if non-scalar.

Required
bool

$unique Optional. Whether the specified metadata key should be unique for the object. If true, and the object already has a value for the specified metadata key, no change will be made. Default false.

Required

Return Value

((int)
| false) The meta ID on success, false on failure.

Function Information

Since Version
2.9.0
Source File
wp-includes/meta.php
Advertisement