Title: Getting first thumbnail from post  &#8211; bug with wp code (?)
Last modified: August 19, 2016

---

# Getting first thumbnail from post – bug with wp code (?)

 *  [Liz Fulghum](https://wordpress.org/support/users/finitejest/)
 * (@finitejest)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/getting-first-thumbnail-from-post-bug-with-wp-code/)
 * I’m working with some code that I found here on the forums to pull the first 
   thumbnail from a post. I’ve actually tried two different methods, but the more
   concise method is this:
 * <?php
    $images =& get_children( ‘post_type=attachment&post_mime_type=image&post_parent
   =’ . $post->ID ); $firstImageSrc = wp_get_attachment_image_src(array_shift(array_keys(
   $images)), ‘thumbnail’); if (empty($firstImageSrc)) { $firstImageSrc[0]=get_template_directory_uri().’/
   images/nopreview.gif’; } ?>
 * The issue that I’m having is that MOST of the time, the function(s) works and
   I see a preview image… but sometimes I don’t.
 * I’ve confirmed the following:
 * – the thumbnail image does exist
    – it’s not a strange file format (or any different
   file format than any of the working ones) – it’s been uploaded the same way as
   all the others.
 * I tried an alternate function for generating the thumbnail and came back with
   the same results.
 * As near as I can figure I can trace it back to the wp_get_attachment_image_src()
   function (which was used in both methods) but I’m not familiar enough with the
   hardcore wordpress innards to troubleshoot further.
 * Anyone else had a similar issue or have any suggestions, or even a work around
   that does not rely on that wp function?
 * Thanks in advance.

The topic ‘Getting first thumbnail from post – bug with wp code (?)’ is closed to
new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Liz Fulghum](https://wordpress.org/support/users/finitejest/)
 * Last activity: [16 years, 11 months ago](https://wordpress.org/support/topic/getting-first-thumbnail-from-post-bug-with-wp-code/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
