Title: Post Thumbnail error
Last modified: August 30, 2016

---

# Post Thumbnail error

 *  Resolved [Piulres](https://wordpress.org/support/users/piulres/)
 * (@piulres)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/post-thumbnail-error/)
 * Already I lost a night’s sleep trying to figure out how to bring the result of
   this code correctly. Must return the feature image. Some kind soul can help?
 * PS: My code return a default image.
 * What’s wrong?
 *     ```
       if ( is_array($main_articles) ) {
           foreach($main_articles as $article) {
               $article = get_post($article); 
   
               $content.= '<h2 style="font-size:13px"><a>ID) . '" style="text-decoration:none;color:#2D2D25" target="_blank">' . $article->post_title . '</a></h2>';
   
               $thumb_id = get_post_thumbnail_id();
               $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'full', true);
               $thumb_url = $thumb_url_array[0];
   
               if ($thumb_url) {
                   $content.= '<span>"' . $thumb_url . '"</span>';
                   $content.= '<a>ID) . '" target="_blank"><img src="' . $thumb_url->ID . '" width="345"></a>';
               }
   
               $content.= '<p>' . ptn_shorten_string(strip_tags($article->post_content), 100) . '</p>';
   
               $content.= '<p></p><a href="' . get_permalink($article) . '">Read more</a></p>';
   
           }
       }
       return $content;
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/post-thumbnail-error/#post-6471398)
 * try
 *     ```
       $thumb_id = get_post_thumbnail_id( $article->ID );
       ```
   
 * [https://codex.wordpress.org/Function_Reference/get_post_thumbnail_id](https://codex.wordpress.org/Function_Reference/get_post_thumbnail_id)
 *  Thread Starter [Piulres](https://wordpress.org/support/users/piulres/)
 * (@piulres)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/post-thumbnail-error/#post-6471401)
 * Michael, I love you so much. Thx. Haha

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Post Thumbnail error’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [thumbnail](https://wordpress.org/support/topic-tag/thumbnail/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [Piulres](https://wordpress.org/support/users/piulres/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/post-thumbnail-error/#post-6471401)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
