Easily get posts with a specific custom field/value on your WordPress blog

May 4, 2009 at 10:01 am

Ever wanted to be able to only get the list of posts which have a specific custom field key as well as a specific value? If yes, just read on. Our friend John Kolbert have this short, but useful recipe for you.

To achieve this recipe, simply find the loop and add the query_posts() function just above, as in the example below:

<?php query_posts('meta_key=review_type&meta_value=movie');  ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

You’ll get the list of post having review_type as a custom field key and movie as a value. Just change theses values to fit your needs.

Credits goes to John Kolbert for this great piece of code!