Title: show thumbnails error
Last modified: August 22, 2016

---

# show thumbnails error

 *  [huenguyenchrish](https://wordpress.org/support/users/huenguyenchrish/)
 * (@huenguyenchrish)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/show-thumbnails-error/)
 * Hi everyone, i want to show up 3 thumbnails by ID on site but have wrong with
   my code, this make only display 1 thumbnail instead of 3
 * this code :
 *     ```
       <div class="gmenu">&raquo; Top Game Hay</div>
       <div class="appContainer" >
       <?php
       global $post;
       $myposts = get_posts(array('numberposts' => '3', 'orderby' => 'rand'));
       foreach($myposts as $post) :
       setup_postdata($post);
       ?>
       <?php
       $thumb_id = get_post_thumbnail_id($post->ID);
       $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
       if(has_post_thumbnail())
       {
       echo '<div class="appPreview">';
       echo '<a href="'.get_post_meta($thumb_id, '_wp_attachment_image_alt', true).'">';
       echo get_the_post_thumbnail($post->ID ,'thumbnail', array( 'class' => 'appImg' ));
       echo '</a><div class="seller">';
       echo the_post_thumbnail_caption();echo '</div>';
       echo '<a class ="download" href="'.get_post_meta($thumb_id, '_wp_attachment_image_alt', true).'" rel="nofollow"> Tải Về</a>';
       echo '</div>';
       } ?>
       <?php endforeach; ?>
       <?php wp_reset_query(); ?>
       <div class="clearing"></div>
       </div>
       ```
   

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/show-thumbnails-error/#post-5458848)
 * do all your posts have a featured image?
 * if not, you could try to query only posts that have a featured image;
 * change:
    `$myposts = get_posts(array('numberposts' => '3', 'orderby' => 'rand'));`
 * to:
    `$myposts = get_posts(array('numberposts' => '3', 'orderby' => 'rand', '
   meta_key' => '_thumbnail_id'));`
 *  Thread Starter [huenguyenchrish](https://wordpress.org/support/users/huenguyenchrish/)
 * (@huenguyenchrish)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/show-thumbnails-error/#post-5458856)
 * huraaa… finally I got it, thank you alchymyth It works perfect 😀

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

The topic ‘show thumbnails error’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [huenguyenchrish](https://wordpress.org/support/users/huenguyenchrish/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/show-thumbnails-error/#post-5458856)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
