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 want to grab the 5 most recent posts that have thumbnails.

share|improve this question
Improve your question: What have you tried already? Where did you get stuck? Which errors did you see? – toscho Mar 17 '12 at 19:01
@toscho I had no idea how to do the query Ryan outlined below with the meta_query. This was really all the information I could supply with the question when I wrote it. – Kit Sunde Mar 17 '12 at 20:34
up vote 20 down vote accepted

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.

share|improve this answer
Boom! Perfect thanks – Joshc Aug 27 '13 at 16:34

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.