WordPress at a glance

wp_update_attachment_metadata() WP 1.0

Update metadata for an attachment.

No Hooks.

Return

Int/true/false. False if $post is invalid.

Usage

wp_update_attachment_metadata( $attachment_id, $data );
$attachment_id(int) (required)
Attachment post ID.
$data(array) (required)
Attachment meta data.

Code of wp_update_attachment_metadata: wp-includes/post.php VER 5.0

<?php
function wp_update_attachment_metadata( $attachment_id, $data ) {
	$attachment_id = (int) $attachment_id;
	if ( ! $post = get_post( $attachment_id ) ) {
		return false;
	}

	/**
	 * Filters the updated attachment meta data.
	 *
	 * @since 2.1.0
	 *
	 * @param array $data          Array of updated attachment meta data.
	 * @param int   $attachment_id Attachment post 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' );
}

Related Functions

From category: Metadata (postmeta)

No comments
    Hello, !     Log In . Register