4

I've just taken over a busy WordPress site that's got ~800 posts so far.

The site's been around long enough that it was started up before post_thumbnails was available. They worked around that shortcoming with a custom field called 'Image' that held a value of the relative path to the image, e.g., "/wp-content/uploads/2012/11/image.jpg"

The theme is using Tim Thumb to make the different thumb sizes.

I'd love to get away from this and just use the post_thumbnails feature and set the sizes in functions.php and get rid of timthumb.php altogether.

I've searched, but haven't found a good way to make the switch. Any suggestions?

5

Had the same issue last week and here is what i did:

if (has_post_thumbnail()) 
    //if the post already has a post thumbnail then just use that
    the_post_thumbnail($size = 'post-thumbnail', $attr = '');
else{
    //if not then convert the custom field to the post thumbnail and display that
    $at_url = get_post_meta($post->ID, 'image', true);
    $at_id = get_image_id_by_url($at_url);
    delete_post_meta($post->ID, 'image');
    if ($at_id){
        set_post_thumbnail($post, $at_id);
        the_post_thumbnail($size = 'post-thumbnail', $attr = '');
    }else{
        //else just display a default image or not :)
    }
}
  • 1
    If I am reading it right, it is intended to modify post thumbnails on the fly as needed but it could pretty easily be modified to loop through all the posts and convert everything at once. +1 – s_ha_dum Dec 9 '12 at 22:11
  • yep, and yep :) – Bainternet Dec 9 '12 at 22:21
  • Thank you so much - this is brilliant! For the get_image_id_by_url function, I used the one posted here: philipnewcomer.net/2012/11/… And the only change I had to make to your function was to append the blog's url to the beginning of my Image field value, since that wasn't being included. – NatalieMac Dec 10 '12 at 2:32

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