I have a code that display the post if has_post_thumpnail the problem is it shows all the posts wheather it has thumpnail or not
<?php
global $post;
$args = array( 'numberposts' => 5 );
$postQuery = get_posts($args);
$num = 0;
foreach( $postQuery as $post ) : setup_postdata($post);
if ( has_post_thumbnail() ) { ?>
<div style="display: inline-block;; ">
<a href="<?php echo get_permalink(); ?>" title="Go to <?php echo the_title(); ?>" rel="bookmark">
<?php the_post_thumbnail('medium'); ?>
</a>
</div>
<div style="display: inline-block; width:50%; vertical-align: top;">
<span style="vertical-align: top;" class="flex-caption"><?php the_title('<h1>','</h1>'); ?>
<?php the_content(); ?>
</span>
</div>
<?php
}
endforeach; ?>
Use this code instead of has_post_thumbnail()
Please refer below link for more information
http://codex.wordpress.org/Function_Reference/has_post_thumbnail