Ben
Ben is a lifelong Nintendo fan who likes to build websites, and make video games. He buys way too much Lego.
WordPress and Games
So – I make WordPress themes – lots of them π
Something that’s bugged me for a while is that I can’t easily use the WP_Query to select posts with featured images. This isn’t functionality that’s needed that often – but it can be desirable for things like image carousels where you need an image to make everything look good.
Today however – I finally found a solution – and it’s surprisingly simple. All post data – including the featured image url – us stored in WordPress post meta, it’s a shame I hadn’t made the connection before. All I have to do to select posts that use featured images is check for the existence of a meta property that is typically hidden.
To do this the query would look something like this:
$args = array( 'meta_key' => '_thumbnail_id' ); $query = new WP_Query( $args );
2 thoughts on “WordPress Query: Exclude Posts With No Featured Image” Leave a comment ›