WordPress.org

Ready to get started?Download WordPress

Codex

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

Function Reference/get metadata

Contents

Description

Retrieve metadata for the specified object.

Usage

<?php get_metadata($meta_type$object_id$meta_key$single)  ?>

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) (optional) Optional. Metadata key. If not specified, retrieve all metadata for the specified object.
Default: empty string
$single
(boolean) (optional) Optional, default is false. If true, return only the first value of the specified meta_key. This parameter has no effect if meta_key is not specified.
Default: false

Return Values

(string,array,bool) 
Single metadata value, or array of values. If the $meta_type or $object_id parameters are invalid, false is returned. If the meta value isn't set, an empty string or array is returned, respectively.

Notes

  • Uses: apply_filters() - Calls 'get_{$meta_type}_metadata' with null, $object_id, $meta_key and $single. If the filtered value is anything other than null, it will be returned and the database and cache won't be queried. Note that if the meta value you wish to return from this filter is an array, it needs to be wrapped inside of another array to achieve the expected result. See ticket #22342.
  • Uses: maybe_unserialize() to unserialize the metadata before it is returned.
  • false may also be returned if the stored data could not be unserialized, which usually happen if the meta_value was changed manually (i.e. when replacing all URLs when migrating the database to a new domain name).

Change Log

Since: 2.9

Source File

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