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've got a highlight section on the header of my website which shows the title and the thumbnail of the last X posts having a thumbnail.

Is there any custom query which allows me to retrieve only the last X post having a thumbnail?

At the moment I'm retrieving the last X * 10 posts (because not all the posts have a thumbnail) hoping that in this result I'll have X posts having a thumbnail. After doing my query I add a condition: if (has_post_thumbnail()).

This solution is really uncertain and ugly, a custom query with a thumbnail parameter would be great but I couldn't find any hint about it.

share|improve this question
up vote 0 down vote accepted

try to work this into your query: 'meta_key' => '_thumbnail_id' http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

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.