How do I get posts that have a thumbnail in WP_Query?

You should be able to call posts with a featured image with the following code:

$thumbs = array(
            'posts_per_page' => 5,
            'meta_query' => array(array('key' => '_thumbnail_id')) 
);
$query = new WP_Query($thumbs);

The code checks each post for the custom field _thumbnail_id, which is where the thumbnail image is stored.

Leave a Comment