views:

11

answers:

2

I just added a new Wordpress thumbnail size using add_image_size call, but now all the photos I already uploaded are not of the correct size. If I request them, all I get is the original image with width and height attributes correctly set.

How can I force the creation of that thumb, saving the data to the database as well, given an attachment ID?

Please note I want to do a simple admin operation or execute code from a theme file.

A: 

I don't know if there's an operation to do this from the admin, but I can execute this code from a theme file:

require(ABSPATH.'wp-admin/includes/image.php');
$file = str_replace('http://www.example.com/', ABSPATH, $attachment->guid);
wp_update_attachment_metadata( $attachment->ID,
    wp_generate_attachment_metadata( $attachment->ID, $file ) );

that recreates all of the thumb sizes at once (don't know if the already created ones are done as well, but it's a one time code execution).

You must replace "www.example.com" with your URL and $attachment with an actual attachment post structure, retrieved with get_post or similar.

iBobo
A: 

This is bug #13947. Instead of the_post_thumbnail() use this code in your theme until the bug is fixed:

the_post_thumbnail(
    array ( 150, 150 ), // size
    array ( 'class' => 'attachment-post-thumbnail' )
);
toscho
Sorry you didn't understand the problem. I don't need need the post thumbnail, but all of the images in the post at a specified size, which got specified after the upload. I use them for a custom coded template for an image gallery. Thanks for your answer anyway.
iBobo