

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.
4 Responses
Loving this. Saved me a lot of work. Just one question. How can I get posts filtered by two custom fields?
I`m building a theme for a website and I need to display on the front page some articles that have two custom fields, and only those articles. New articles will be added so filtering them by ID isn`t an option.
Thank you and keep up the good work!
I am having custom field ‘city’ for multiple posts,
and I need to display distinct city names with posts count,
e.g:London (13)
Paris (10)
where 13 and 10 are number of posts means there are 13 posts having custom field ‘city’ value as ‘London’.
what will be the query?
$query = new WP_Query(array(‘post_type’=>’post’,'cat’=>’17′,’meta_key’=>’City’,'groupby’=>’meta_value’));
did not worked.
Thanks. I was looking for either get_posts or WP_Query to count a specific post type with a specific custom field value. This solved my problem.
One thing: Looking at hira’s post, he used groupby when he should have used meta_value.
@Hira: If you see my comment, try changing it.
Bruce
What should I do if I wanted to recover those post that had more than one custom field value?
For example: Cities with parks, airports, and beach. (just an example)
Trackbacks: