wp_get_attachment_metadata( int $attachment_id, bool $unfiltered = false )

Retrieve attachment meta field for attachment ID.


Description Description


Parameters Parameters

$attachment_id

(int) (Required) Attachment post ID. Defaults to global $post.

$unfiltered

(bool) (Optional) If true, filters are not run.

Default value: false


Top ↑

Return Return

(mixed) Attachment meta field. False on failure.


Top ↑

Source Source

File: wp-includes/post.php

function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
	$attachment_id = (int) $attachment_id;
	if ( ! $post = get_post( $attachment_id ) ) {
		return false;
	}

	$data = get_post_meta( $post->ID, '_wp_attachment_metadata', true );

	if ( $unfiltered )
		return $data;

	/**
	 * Filters the attachment meta data.
	 *
	 * @since 2.1.0
	 *
	 * @param array|bool $data          Array of meta data for the given attachment, or false
	 *                                  if the object does not exist.
	 * @param int        $attachment_id Attachment post ID.
	 */
	return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by Codex

    Example return value

    Array
    (
    	[width] => 2400
    	[height] => 1559
    	[file] => 2011/12/press_image.jpg
    	[sizes] => Array
    	(
    		[thumbnail] => Array
    		(
    			[file] => press_image-150x150.jpg
    			[width] => 150
    			[height] => 150
    			[mime-type] => image/jpeg
    		)
    		[medium] => Array
    		(
    			[file] => press_image-4-300x194.jpg
    			[width] => 300
    			[height] => 194
    			[mime-type] => image/jpeg
    		)
    		[large] => Array
    		(
    			[file] => press_image-1024x665.jpg
    			[width] => 1024
    			[height] => 665
    			[mime-type] => image/jpeg
    		)
    		[post-thumbnail] => Array
    		(
    			[file] => press_image-624x405.jpg
    			[width] => 624
    			[height] => 405
    			[mime-type] => image/jpeg
    		)
    	)
    	[image_meta] => Array
    	(
    		[aperture] => 5
    		[credit] => 
    		[camera] => Canon EOS-1Ds Mark III
    		 => 
    		[created_timestamp] => 1323190643
    		[copyright] => 
    		[focal_length] => 35
    		[iso] => 800
    		[shutter_speed] => 0.016666666666667
    		[title] => 
    	)
    )
    
    

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