How to get_posts having post thumbnail?

I have following code:

$posts = get_posts(array(
  "meta_key" => "special",
  "meta_value" => "surprise",
  // "has_post_thumbnail" => true, // how to do that?
));

What should I do to select posts having post thumbnails?

Related posts

Leave a Reply

1 comment

  1. The thumbnail is stored as a meta with a key of _thumbnail_id, so that could be used to find posts that have thumbnails. Something like this:

    $query = new WP_Query(array(
        'meta_query' => array( array( 
            'key' => '_thumbnail_id',
            'value' => '0',
            'compare' => '>=',
            )
        )
    ));