get_metadata

The timeline below displays how wordpress function get_metadata has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Retrieves the value of a metadata field for the specified object type and ID.
 *
 * If the meta field exists, a single value is returned if `$single` is true,
 * or an array of values if it's false.
 *
 * If the meta field does not exist, the result depends on get_metadata_default().
 * By default, an empty string is returned if `$single` is true, or an empty array
 * if it's false.
 *
 * @since 2.9.0
 *
 * @see get_metadata_raw()
 * @see get_metadata_default()
 *
 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                          or any other object type with an associated meta table.
 * @param int    $object_id ID of the object metadata is for.
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 *                          the specified object. Default empty string.
 * @param bool   $single    Optional. 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 mixed An array of values if `$single` is false.
 *               The value of the meta field if `$single` is true.
 *               False for an invalid `$object_id` (non-numeric, zero, or negative value),
 *               or if `$meta_type` is not specified.
 *               An empty string if a valid but non-existing object ID is passed.
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    $value = get_metadata_raw($meta_type, $object_id, $meta_key, $single);
    if (!is_null($value)) {
        return $value;
    }
    return get_metadata_default($meta_type, $object_id, $meta_key, $single);
}

WordPress Version: 5.8

/**
 * Retrieves the value of a metadata field for the specified object type and ID.
 *
 * If the meta field exists, a single value is returned if `$single` is true,
 * or an array of values if it's false.
 *
 * If the meta field does not exist, the result depends on get_metadata_default().
 * By default, an empty string is returned if `$single` is true, or an empty array
 * if it's false.
 *
 * @since 2.9.0
 *
 * @see get_metadata_raw()
 * @see get_metadata_default()
 *
 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                          or any other object type with an associated meta table.
 * @param int    $object_id ID of the object metadata is for.
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 *                          the specified object. Default empty.
 * @param bool   $single    Optional. 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 mixed An array of values if `$single` is false.
 *               The value of the meta field if `$single` is true.
 *               False for an invalid `$object_id` (non-numeric, zero, or negative value),
 *               or if `$meta_type` is not specified.
 *               An empty string if a valid but non-existing object ID is passed.
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    $value = get_metadata_raw($meta_type, $object_id, $meta_key, $single);
    if (!is_null($value)) {
        return $value;
    }
    return get_metadata_default($meta_type, $object_id, $meta_key, $single);
}

WordPress Version: 5.5

/**
 * Retrieves the value of a metadata field for the specified object type and ID.
 *
 * If the meta field exists, a single value is returned if `$single` is true,
 * or an array of values if it's false.
 *
 * If the meta field does not exist, the result depends on get_metadata_default().
 * By default, an empty string is returned if `$single` is true, or an empty array
 * if it's false.
 *
 * @since 2.9.0
 *
 * @see get_metadata_raw()
 * @see get_metadata_default()
 *
 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                          or any other object type with an associated meta table.
 * @param int    $object_id ID of the object metadata is for.
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 *                          the specified object. Default empty.
 * @param bool   $single    Optional. 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 mixed Single metadata value, or array of values.
 *               False if there's a problem with the parameters passed to the function.
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    $value = get_metadata_raw($meta_type, $object_id, $meta_key, $single);
    if (!is_null($value)) {
        return $value;
    }
    return get_metadata_default($meta_type, $object_id, $meta_key, $single);
}

WordPress Version: 5.4

/**
 * Retrieves metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                          or any other object type with an associated meta table.
 * @param int    $object_id ID of the object metadata is for.
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 *                          the specified object. Default empty.
 * @param bool   $single    Optional. 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 mixed Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filters whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, term, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id ID of the object metadata is for.
     * @param string            $meta_key  Metadata key.
     * @param bool              $single    Whether to return only the first value of the specified $meta_key.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        if (isset($meta_cache[$object_id])) {
            $meta_cache = $meta_cache[$object_id];
        } else {
            $meta_cache = null;
        }
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 5.3

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int    $object_id ID of the object metadata is for
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 *                          the specified object.
 * @param bool   $single    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.
 * @return mixed Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filters whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, term, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param bool              $single    Whether to return only the first value of the specified $meta_key.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        if (isset($meta_cache[$object_id])) {
            $meta_cache = $meta_cache[$object_id];
        } else {
            $meta_cache = null;
        }
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 5.1

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int    $object_id ID of the object metadata is for
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 *                          the specified object.
 * @param bool   $single    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.
 * @return mixed Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filters whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, term, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param bool              $single    Whether to return only the first value of the specified $meta_key.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 9.9

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int    $object_id ID of the object metadata is for
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 * 		                    the specified object.
 * @param bool   $single    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.
 * @return mixed Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filters whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, term, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param bool              $single    Whether to return only the first value of the specified $meta_key.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 9.3

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int    $object_id ID of the object metadata is for
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 * 		                    the specified object.
 * @param bool   $single    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.
 * @return mixed Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filters whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param bool              $single    Whether to return only the first value of the specified $meta_key.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: .20

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int    $object_id ID of the object metadata is for
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 * 		                    the specified object.
 * @param bool   $single    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.
 * @return mixed Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filters whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, term, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param bool              $single    Whether to return only the first value of the specified $meta_key.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 9.2

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int    $object_id ID of the object metadata is for
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 * 		                    the specified object.
 * @param bool   $single    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.
 * @return mixed Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filters whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param bool              $single    Whether to return only the first value of the specified $meta_key.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: .10

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int    $object_id ID of the object metadata is for
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 * 		                    the specified object.
 * @param bool   $single    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.
 * @return mixed Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filters whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, term, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param bool              $single    Whether to return only the first value of the specified $meta_key.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 4.6

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int    $object_id ID of the object metadata is for
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 * 		                    the specified object.
 * @param bool   $single    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.
 * @return mixed Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filters whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param bool              $single    Whether to return only the first value of the specified $meta_key.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 4.4

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int    $object_id ID of the object metadata is for
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 * 		                    the specified object.
 * @param bool   $single    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.
 * @return mixed Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filter whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param bool              $single    Whether to return only the first value of the specified $meta_key.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 4.3

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int    $object_id ID of the object metadata is for
 * @param string $meta_key  Optional. Metadata key. If not specified, retrieve all metadata for
 * 		                    the specified object.
 * @param bool   $single    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.
 * @return mixed Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filter whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should
     *                                     return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param string|array      $single    Meta value, or an array of values.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 4.2

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int $object_id ID of the object metadata is for
 * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for
 * 		the specified object.
 * @param bool $single 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.
 * @return mixed Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filter whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should
     *                                     return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param string|array      $single    Meta value, or an array of values.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 4.1

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int $object_id ID of the object metadata is for
 * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for
 * 		the specified object.
 * @param bool $single 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.
 * @return string|array Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filter whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should
     *                                     return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param string|array      $single    Meta value, or an array of values.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 4.0

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int $object_id ID of the object metadata is for
 * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for
 * 		the specified object.
 * @param bool $single 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.
 * @return string|array Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    /**
     * Filter whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, $meta_type, refers to the meta
     * object type (comment, post, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should
     *                                     return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param string|array      $single    Meta value, or an array of values.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 3.9

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int $object_id ID of the object metadata is for
 * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for
 * 		the specified object.
 * @param bool $single 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.
 * @return string|array Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type) {
        return false;
    }
    if (!$object_id = absint($object_id)) {
        return false;
    }
    /**
     * Filter whether to retrieve metadata of a specific type.
     *
     * The dynamic portion of the hook, $meta_type, refers to the meta
     * object type (comment, post, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 3.1.0
     *
     * @param null|array|string $value     The value get_metadata() should
     *                                     return - a single metadata value,
     *                                     or an array of values.
     * @param int               $object_id Object ID.
     * @param string            $meta_key  Meta key.
     * @param string|array      $single    Meta value, or an array of values.
     */
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}

WordPress Version: 3.7

/**
 * Retrieve metadata for the specified object.
 *
 * @since 2.9.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int $object_id ID of the object metadata is for
 * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for
 * 		the specified object.
 * @param bool $single 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.
 * @return string|array Single metadata value, or array of values
 */
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
    if (!$meta_type) {
        return false;
    }
    if (!$object_id = absint($object_id)) {
        return false;
    }
    $check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
    if (null !== $check) {
        if ($single && is_array($check)) {
            return $check[0];
        } else {
            return $check;
        }
    }
    $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
    if (!$meta_cache) {
        $meta_cache = update_meta_cache($meta_type, array($object_id));
        $meta_cache = $meta_cache[$object_id];
    }
    if (!$meta_key) {
        return $meta_cache;
    }
    if (isset($meta_cache[$meta_key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$meta_key][0]);
        } else {
            return array_map('maybe_unserialize', $meta_cache[$meta_key]);
        }
    }
    if ($single) {
        return '';
    } else {
        return array();
    }
}