0

I'm using a plugin called Exifography. They provide the capability to use filters to adjust for your purposes. In the example provided I'm simply trying to get the height & width of the image and return it.

This works great on the attachment page (image.php) but will not work with posts. I can't figure out how to properly get the image ID in order to query the wp_get_attachment_metadata function.

This will be used on posts with multiple images.

function massage_exif($content,$postID,$imgID){
  $imgmeta = wp_get_attachment_metadata($imgID);
  $width= $imgmeta['image_meta']['width'];
  $height = $imgmeta['image_meta']['height'];
  array_push($content,$height . 'x' . $width);
return $content;
add_filter('exifography_display_exif','massage_exif');

Using ver 4.01 of WP

2 Answers 2

0

If you know the image ID, you could try this function: http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

3
  • Unfortunately, that is exactly what I can't seem to find.
    – Eddie
    Commented Dec 9, 2014 at 18:43
  • In the function parameters, isn't either $postID or $imgID the attachment ID?
    – Dan
    Commented Dec 9, 2014 at 21:40
  • That is what I would think it would be... but no. When this filter runs in the image.php template it works. So, it is getting $imgID there. However, when run in a normal post, it does not. I'm completely baffled on this issue. I can't help but think I'm missing something fundamental.
    – Eddie
    Commented Dec 9, 2014 at 23:18
0

Well, after some discussion with the developer, I was missing some key items in the add_filter line. I needed to pass along the "11","3". The three is the important item here. It is the number of variables to passback... the 3rd being the elusive $imgID.

function massage_exif($content,$postID,$imgID){
  $imgmeta = wp_get_attachment_metadata($imgID);
  $width= $imgmeta['image_meta']['width'];
  $height = $imgmeta['image_meta']['height'];
  array_push($content,$height . 'x' . $width);
return $content;
add_filter('exifography_display_exif','massage_exif',11,3);

Thanks for helping me keep digging until and answer was found.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.