Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Display correct image attachments AFTER being edited in WP WordPress

  • SOLVED

Hello WP Answerers!

I'm using code which correctly display's a posts attachments but if I edit the attached image using the WP edit image feature (i.e. to correct an image's orientation), the resulting code continues to display the original image and not the newly saved edited version of the image (and yes, I save changes to the gallery and then update the post).

The code I have is as follows:


<div class="photo-holder">
<?php
$args = array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
echo wp_get_attachment_image($attachment->ID, 'post-576');
}
}
?>
</div>


As I mentioned earlier, this code works great as long as I don't need to edit any of the attachments for a given post. If however, some of the attached images have the incorrect orientation, and I edit and save these images to have the correct orientation, then the above code will not display the correct edited version but instead continue to display the original.

Example (see the 6th, 7th & 8th images on this post which are oriented incorrectly although I've edited the image in the post and it appears correctly in the gallery edit screen):

http://www.ottawafusion.ca/2011/11/gee-gees-game-%E2%80%93-13u-girls-team-outing/

Look forward to a simple fix!

Answers (2)

2011-11-01

Fahad Murtaza answers:

Your current code for getting attached image is


echo wp_get_attachment_image($attachment->ID, 'post-576');


You should try something like following where $size is the striong containing the size name for your image.



<?php wp_get_attachment_image( $attachment->ID, $size, $icon, $attr ); ?>


Also please tell me what is 'post-576'

technically you should be good just with


echo wp_get_attachment_image($attachment->ID);


Edit:
which will give you the thumbnail by default. Since you are looking for the new full image after editing, here is the solution


echo wp_get_attachment_image( $attachment->ID, 'full' );


ZedGee comments:

Greetings Fahd,

I will try this.

post-576 is a custom image size declared in functions.php:


if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 50, 50, true ); // Normal post thumbnails
add_image_size( 'post-thumbnail',192,90, true );
add_image_size( 'gallery-thumbnail',576,576, true );
add_image_size( 'post-576',576,9999, False );
}


ZedGee comments:

Re. your edit - this is already what is in the existing code:

echo wp_get_attachment_image($attachment->ID, 'post-576');


Fahad Murtaza comments:

OK

Lets try regenerating all image sizes again from original images.

Use this plugin and see if it works

http://wordpress.org/extend/plugins/regenerate-thumbnails/


ZedGee comments:

This plugin does the trick although it would be nice to be able to handle this within the post instead of in the image library....

Thanks and cheers!

2011-11-01

Jurre Hanema answers:

Is 'post-576' really an existing image size you have registered?

Are you sure you are applying the transformation to all image sizes (in the edit screen, select "All image sizes" for "Apply changes to")?


ZedGee comments:

Hi Jurre,

Yes, post-576 exists and is working correctly:

if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 50, 50, true ); // Normal post thumbnails
add_image_size( 'post-thumbnail',192,90, true );
add_image_size( 'gallery-thumbnail',576,576, true );
add_image_size( 'post-576',576,9999, False );
}


When an existing attached image is edited using Edit Image in WP, it seems to create a new image file. For example:

Original:

http://www.ottawafusion.ca/wp-content/uploads/2011/11/2011_10_31_191005_IMG_6295_2759.jpg

Edited:

http://www.ottawafusion.ca/wp-content/uploads/2011/11/2011_10_31_191005_IMG_6295_2759-e1320164856970.jpg

When editing, Apply changes to ALL IMAGE SIZES is checked....


Jurre Hanema comments:

Yeah, after some fooling around I am now having the same issue. Haven't been able to figure it out yet...


ZedGee comments:

Greetings Jurre,

Thanks for your help but Fahd has an acceptable solution that is working....