WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/add metadata

Contents

Description

Add metadata for the specified object in WordPress.

NOTE: This is a generic, low level function and should not be used directly by plugins or themes. Instead, use the corresponding meta functions for the object type you're working with:

Usage

<?php add_metadata$meta_type$object_id$meta_key$meta_value ); ?>

Parameters

$meta_type
(string) (required) Type of object the metadata is for (e.g., comment, post, or user). Always singular.
Default: None
$object_id
(integer) (required) The ID of the object metadata is for.
Default: None
$meta_key
(string) (required) A metadata key (as in 'key'=>'value').
Default: None
$meta_value
(string) (required) A metadata value (as in 'key'=>'value').
Default: None
$unique
(boolean) (Optional) This determines whether the specified key can have multiple entries for the specified object id. If false, add_metadata() will add duplicate keys to the object. If true, nothing will be added if the specified key already exists for the specified id.
Default: False

Return Values

(boolean|integer) 
Returns false on failure. On success, returns the ID of the inserted row. However, note that the return value may instead be the result of the 'add_{$meta_type}_metadata' filter.

Notes

  • Uses: $wpdb
  • Uses: apply_filters() - Calls 'add_{$meta_type}_metadata' with null and each of the parameters passed to the function. If the result of this filter call is anything other than null, the function will be short-circuited and the result will be returned.
  • Uses: do_action() - Calls 'added_{$meta_type}_meta' if the metadata was added successfully with the ID of the new row in the meta table and the first three function parameters.

Change Log

Source File

add_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.