WordPress:: Get information about image uploaded in media gallery
Inorder to get information about image uploaded to media gallery, wp_get_attachment_metadata($image_id) method proves very useful.
The param to be passed to this method is the image id, corresponding to which we want to obtain the data.
The information that this method returns is in the format:
Array ( [width] => 1920 [height] => 1079 [hwstring_small] => height='71' width='128' [file] => 2012/10/nfs_shift_bmw_gt2_render_bmp_jpgcopy.jpg [sizes] => Array ( [thumbnail] => Array ( [file] => nfs_shift_bmw_gt2_render_bmp_jpgcopy-150x150.jpg [width] => 150 [height] => 150 ) => Array ( [file] => nfs_shift_bmw_gt2_render_bmp_jpgcopy-300x168.jpg [width] => 300 [height] => 168 ) [large] => Array ( [file] => nfs_shift_bmw_gt2_render_bmp_jpgcopy-1024x575.jpg [width] => 1024 [height] => 575 ) [post-thumbnail] => Array ( [file] => nfs_shift_bmw_gt2_render_bmp_jpgcopy-940x198.jpg [width] => 940 [height] => 198 ) ) [image_meta] => Array ( [aperture] => 0 [credit] => [camera] => => [created_timestamp] => 0 [copyright] => [focal_length] => 0 [iso] => 0 [shutter_speed] => 0 [title] => ) ) Now,there is a small catch: The data that this method returns contains fields named title, caption but their values always appear BLANK. In order to get these values we can query the WP table posts like this and obtain the missing information : SELECT post_content as description, post_title as title, post_excerpt as caption FROM posts WHERE ID = <image_id>; This will get you the remaining data (title, caption and description). To get the alt tag associated with this post use this:- $alt = get_post_meta($image_id, '_wp_attachment_image_alt', true);