wp_update_attachment_metadata( int $attachment_id, array $data ): int|false

In this article

Updates metadata for an attachment.

Parameters

$attachment_idintrequired
Attachment post ID.
$dataarrayrequired
Attachment meta data.

Return

int|false False if $post is invalid.

Source

function wp_update_attachment_metadata( $attachment_id, $data ) {
	$attachment_id = (int) $attachment_id;

	$post = get_post( $attachment_id );

	if ( ! $post ) {
		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.
	 */
	$data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );
	if ( $data ) {
		return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
	} else {
		return delete_post_meta( $post->ID, '_wp_attachment_metadata' );
	}
}

Hooks

apply_filters( ‘wp_update_attachment_metadata’, array $data, int $attachment_id )

Filters the updated attachment meta data.

Changelog

VersionDescription
2.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.