get_<meta_type>_metadata

Filters whether to retrieve metadata of a specific type.

Description

apply_filters( 'get_<meta_type>_metadata', (null) $null, (int) $object_id, (string) $meta_key, (bool) $single ); 

The dynamic portion(s) of the hook refer to the meta object type (comment, post, or user). Returning a non-null value will effectively short-circuit the function.

Parameters (4)

0. $null (null) => null
The value get_metadata() should return - a single metadata value, or an array of values.
1. $object_id (int)
The object id.
2. $meta_key (string)
The meta key.
3. $single (bool)
Whether to return only the first value of the specified $meta_key.

Usage

To run the hook, copy the example below.
  1. $null = apply_filters( 'get_{$meta_type}_metadata', $null, $object_id, $meta_key, $single ); 
  2.  
  3. if ( !empty( $null ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the get_<meta_type>_metadata callback 
  2. function filter_get_meta_type_metadata( $null, $object_id, $meta_key, $single ) { 
  3. // make filter magic happen here... 
  4. return $null
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( "get_{$meta_type}_metadata", 'filter_get_meta_type_metadata', 10, 4 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( "get_{$meta_type}_metadata", 'filter_get_meta_type_metadata', 10, 4 ); 

Defined (2)

The filter is defined in the following location(s).

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