Slides for my workshop on querying creatively for WordCamp Cape Town 2015

From the workshop page on the WordCamp Cape Town site:

We’re at a point now where we have these incredibly powerful query classes in WordPress core that allow you to really tailor down to whatever criterion you want. In this workshop, Drew will provide some real-world examples of some crazy stuff you can do with queries – it’s very much a “sky’s the limit” kind of situation. Queries are really interesting and powerful, and a lot of people are intimidated by advanced queries, even with the abstraction layers that WordPress has put in place.

 

Query based on whether posts have a featured image

Ever need to query for posts based whether they have a post thumbnail? This can be accomplished by adding 'meta_key' => '_thumbnail_id' to the query args:

<?php
$args = array(
	'posts_per_page' => 1,
	'meta_key' => '_thumbnail_id'
);
$my_query = new WP_Query( $args );

if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post();
...