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

Function Reference/add metadata


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:


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


(string) (required) Type of object the metadata is for (e.g., comment, post, or user). Always singular.
Default: None
(integer) (required) The ID of the object metadata is for.
Default: None
(string) (required) A metadata key (as in 'key'=>'value').
Default: None
(string) (required) A metadata value (as in 'key'=>'value').
Default: None
(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

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.


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


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

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