Query posts only with featured image
I want to query 6 posts, but only those which have a featured image attached. I am using meta_key
method for this with WP_Query
as such:
$args = array(
'post_type' = 'post',
'meta_key' = '_thumbnail_id',
'post_count' = 6 );
$query = new WP_Query($args);
Followed by
?php while($query-have_posts()) : $query-the_post(); ?
h2?php the_title(); ?/h2
?php the_post_thumbnail('thumbnail'); ?
?php endwhile; ?
This doesn't seem to work. The query is returning more than 6 posts and also those which don't have a featured image. Any ideas what I've got wrong here?
@chip: var_dump($query);
gives a large result so I have posted it in a pastebin
Topic post-thumbnails wp-query Wordpress
Category Web