wp_get_attachment_metadata

Retrieve attachment meta field for attachment ID.

Description

wp_get_attachment_metadata( (int) $post_id = 0, (bool) $unfiltered = false ); 

Parameters (2)

0. $post_id — Optional. (int)
Attachment ID. Default 0.
1. $unfiltered — Optional. (bool) => false
If true, filters are not run. Default false.

Usage

  1. if ( !function_exists( 'wp_get_attachment_metadata' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Attachment ID. Default 0. 
  5. $post_id = -1; 
  6.  
  7. // Optional. If true, filters are not run. Default false. 
  8. $unfiltered = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_get_attachment_metadata($post_id, $unfiltered); 
  12.  

Defined (1)

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

/wp-includes/post.php  
  1. function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) { 
  2. $post_id = (int) $post_id; 
  3. if ( !$post = get_post( $post_id ) ) 
  4. return false; 
  5.  
  6. $data = get_post_meta( $post->ID, '_wp_attachment_metadata', true ); 
  7.  
  8. if ( $unfiltered ) 
  9. return $data; 
  10.  
  11. /** 
  12. * Filters the attachment meta data. 
  13. * @since 2.1.0 
  14. * @param array|bool $data Array of meta data for the given attachment, or false 
  15. * if the object does not exist. 
  16. * @param int $post_id Attachment ID. 
  17. */ 
  18. return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID );