Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.