Support » Plugins » Hacks » Reassigning post thumbnail issue

  • Hi,

    I’m working on a site and I’m trying to make it search through the images in the post to come up with a post thumbnail.

    The thing is, when you add the image to the post while creating it, it picks the thumbnail straight away, but when you add an image after the post has been published, it doesn’t change the already assigned default image.

    Here is the code for the thumbnails:

    // Get image attachment (sizes: thumbnail, medium, full)
    function get_thumbnail($postid=0, $size='full') {
    	if ($postid<1)
    	$postid = get_the_ID();
    	$thumb_key = get_theme_mod('thumb_key');
    		$thumb_key = $thumb_key;
    		$thumb_key = 'thumb';
    	$thumb = get_post_meta($postid, $thumb_key, TRUE); // Declare the custom field for the image
    	if ($thumb != null or $thumb != '') {
    		return $thumb;
    	} elseif ($images = get_children(array(
    		'post_parent' => $postid,
    		'post_type' => 'attachment',
    		'numberposts' => '1',
    		'post_mime_type' => 'image', ))) {
    		foreach($images as $image) {
    			$thumbnail=wp_get_attachment_image_src($image->ID, $size);
    			return $thumbnail[0];
    	} else {
    		return get_bloginfo ( 'stylesheet_directory' ).'/images/login-logo2.jpg';

    And here is the website ->

    Most of the posts with the issue have the “ugometrics” logo as the thumbnail, for your consideration.

    Any ideas?


Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    Obviously you need script to set a new thumbnail when the post is updated. You can hook the ‘publish_to_publish’ action to only capture updates and not new posts. The question is what image to use if there is more than one?

    You can get the last image inserted by choosing the last element in the returned array of attachments because it is sorted by date by default. Whether that would be an appropriate thumbnail I don’t know. I don’t see how a script could possibly know that.

Viewing 1 replies (of 1 total)
  • The topic ‘Reassigning post thumbnail issue’ is closed to new replies.