get_(meta_type)_metadata filter-hookWP 3.1.0

Short-circuits the return value of a meta field.

The dynamic portion of the hook name, $meta_type, refers to the meta object type (post, comment, term, user, or any other type with an associated meta table). Returning a non-null value will effectively short-circuit the function.

Possible filter names include:

Usage

add_filter( 'get_(meta_type)_metadata', 'wp_kama_get_meta_type_metadata_filter', 10, 5 );

/**
 * Function for `get_(meta_type)_metadata` filter-hook.
 * 
 * @param mixed  $value     The value to return, either a single metadata value or an array of values depending on the value of `$single`.
 * @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`.
 * @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.
 *
 * @return mixed
 */
function wp_kama_get_meta_type_metadata_filter( $value, $object_id, $meta_key, $single, $meta_type ){

	// filter...
	return $value;
}
$value(mixed)
The value to return, either a single metadata value or an array of values depending on the value of $single.
Default: null
$object_id(int)
ID of the object metadata is for.
$meta_key(string)
Metadata key.
$single(true|false)
Whether to return only the first value of the specified $meta_key.
$meta_type(string)
Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', or any other object type with an associated meta table.

Changelog

Since 3.1.0 Introduced.
Since 5.5.0 Added the $meta_type parameter.

Where the hook is called

get_metadata_raw()
get_(meta_type)_metadata
metadata_exists()
get_(meta_type)_metadata
wp-includes/meta.php 635
$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single, $meta_type );
wp-includes/meta.php 748
$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true, $meta_type );

Where the hook is used in WordPress

wp-admin/includes/class-wp-site-icon.php 74
add_filter( 'get_post_metadata', array( $this, 'get_post_metadata' ), 10, 4 );
wp-includes/default-filters.php 130
add_filter( 'get_term_metadata', 'wp_check_term_meta_support_prefilter' );
wp-includes/ms-default-filters.php 61
add_filter( 'get_blog_metadata', 'wp_check_site_meta_support_prefilter' );
wp-includes/revision.php 879
add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 );
wp-includes/revision.php 880
add_filter( 'get_post_metadata', '_wp_preview_meta_filter', 10, 4 );