wp_update_attachment_metadata
Update metadata for an attachment.
Description
Returns (int|bool)
False if $post is invalid.
Parameters (2)
- 0. $post_id (int)
- Attachment ID.
- 1. $data (array)
- Attachment data.
Usage
if ( !function_exists( 'wp_update_attachment_metadata' ) ) { require_once ABSPATH . WPINC . '/post.php'; } // Attachment ID. $post_id = -1; // Attachment data. $data = array(); // NOTICE! Understand what this does before running. $result = wp_update_attachment_metadata($post_id, $data);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/post.php
- function wp_update_attachment_metadata( $post_id, $data ) {
- $post_id = (int) $post_id;
- if ( !$post = get_post( $post_id ) )
- return false;
- /**
- * Filters the updated attachment meta data.
- *
- * @since 2.1.0
- *
- * @param array $data Array of updated attachment meta data.
- * @param int $post_id Attachment ID.
- */
- if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) )
- return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
- else
- return delete_post_meta( $post->ID, '_wp_attachment_metadata' );
- }