wp_update_attachment_metadata

Update metadata for an attachment.

Description

(int|bool) wp_update_attachment_metadata( (int) $post_id, (array) $data ); 

Returns (int|bool)

False if $post is invalid.

Parameters (2)

0. $post_id (int)
Attachment ID.
1. $data (array)
Attachment data.

Usage

  1. if ( !function_exists( 'wp_update_attachment_metadata' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Attachment ID. 
  5. $post_id = -1; 
  6.  
  7. // Attachment data. 
  8. $data = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_update_attachment_metadata($post_id, $data); 
  12.  

Defined (1)

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

/wp-includes/post.php  
  1. function wp_update_attachment_metadata( $post_id, $data ) { 
  2. $post_id = (int) $post_id; 
  3. if ( !$post = get_post( $post_id ) ) 
  4. return false; 
  5.  
  6. /** 
  7. * Filters the updated attachment meta data. 
  8. * @since 2.1.0 
  9. * @param array $data Array of updated attachment meta data. 
  10. * @param int $post_id Attachment ID. 
  11. */ 
  12. if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) 
  13. return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); 
  14. else 
  15. return delete_post_meta( $post->ID, '_wp_attachment_metadata' );