WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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' => '>=',
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.