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

User:Jneuenhaus/Metadata API

This article is a ROUGH DRAFT. The author is still working on this document, so please do not edit this without the author's permission. The content within this article may not yet be verified or valid. This information is subject to change.


The Metadata API that can be used to retrieve and manipulate meta data, regardless of the 'type' of meta data; located in /wp-includes/meta.php (code). WordPress stores the comment, post, and user meta data types in the WordPress database.

Note: This information applies to WordPress Version 2.9 and higher. Before Version 2.9, meta data was only handled by functions unique to the meta_type.

Meta Data Functions

add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = false) Adds metadata to a table. Must define either $meta_type or $meta_key to return something.


$meta_type (String - Possible Values: user, comment, post)

$object_id (Integer - {$meta_type}_id: ID of current object)

$meta_key (String - value assigned to key)

$meta_value (String - value assigned to object/key pair)

$unique (Boolean - If set to true, the specified meta key already exists, the function returns false and makes no changes; otherwise, it returns true.)

Parameters include: type ('comment', 'post', 'user', etc), the ID of the content, the meta data key/value pair and determines if the information must be unique (true or false).

delete_metadata($meta_type, $object_id, $meta_key, $meta_value = , $delete_all = false) Removes metadata from a table.

get_metadata($meta_type, $object_id, $meta_key = , $single = false) Retrieves metadata 'value' for the specified 'type', 'object ID', and 'key' for ***.

update_meta_cache($meta_type, $object_ids) Updates metadata cache for the specified 'type' and 'object ID'.

_get_meta_table($type) Retrieves all metadata key/value pairs based on the specified 'type' (e.g 'user').

Reference: Meta Data Types

Function Reference

Filter Functions