get_registered_metadata

Retrieves registered metadata for a specified object.

Description

get_registered_metadata( (string) $object_type, (int) $object_id, (string) $meta_key = '' ); 

Parameters (3)

0. $object_type (string)
Type of object to request metadata for. (e.g. comment, post, term, user)
1. $object_id (int)
ID of the object the metadata is for.
2. $meta_key — Optional. (string) => ''
Registered metadata key. If not specified, retrieve all registered metadata for the specified object.

Usage

  1. if ( !function_exists( 'get_registered_metadata' ) ) { 
  2. require_once ABSPATH . WPINC . '/meta.php'; 
  3.  
  4. // Type of object to request metadata for. (e.g. comment, post, term, user) 
  5. $object_type = ''; 
  6.  
  7. // ID of the object the metadata is for. 
  8. $object_id = -1; 
  9.  
  10. // Optional. Registered metadata key. If not specified, retrieve all registered 
  11. // metadata for the specified object. 
  12. $meta_key = ''; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = get_registered_metadata($object_type, $object_id, $meta_key); 
  16.  

Defined (1)

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

/wp-includes/meta.php  
  1. function get_registered_metadata( $object_type, $object_id, $meta_key = '' ) { 
  2. if ( ! empty( $meta_key ) ) { 
  3. if ( ! registered_meta_key_exists( $object_type, $meta_key ) ) { 
  4. return false; 
  5. $meta_keys = get_registered_meta_keys( $object_type ); 
  6. $meta_key_data = $meta_keys[ $meta_key ]; 
  7.  
  8. $data = get_metadata( $object_type, $object_id, $meta_key, $meta_key_data['single'] ); 
  9.  
  10. return $data; 
  11.  
  12. $data = get_metadata( $object_type, $object_id ); 
  13.  
  14. $meta_keys = get_registered_meta_keys( $object_type ); 
  15. $registered_data = array(); 
  16.  
  17. // Someday, array_filter() 
  18. foreach ( $meta_keys as $k => $v ) { 
  19. if ( isset( $data[ $k ] ) ) { 
  20. $registered_data[ $k ] = $data[ $k ]; 
  21.  
  22. return $registered_data;