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?

1 Answer
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' => '>=',
        )
    )
));

Leave a Reply

Your email address will not be published. Required fields are marked *