Meta Queries

You can query for posts based on their metadata using a Meta Query.

For instance, WordPress stores the featured image using the _thumbnail_id meta key. To display the most recent posts that have a featured image, use:

[display-posts meta_key="_thumbnail_id"]

You can also sort resorts by meta keys. See the tutorial on displaying popular posts by share count as an example.

You can also find posts that have a specific value in their meta key. To display every page using the “full-width.php” page template, use:

[display-posts post_type="page" meta_key="_wp_page_template" meta_value="full-width.php"]

Published by Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributor to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.