I have a winery website with the custom post type "wine", each wine has various custom meta fields like "vintage", "pH", "Varietal-Composition" etc...

Now, i would like to list all wines where vintage=2005.

Any pointers?

2 Answers 2


Check this : Get posts by meta data OR title

The first piece of code is working and allow to make a query based on meta data

You could just get rid of useless stuff (or adapt if you want to use several keys) :

$args = array(
 'post_type' => 'wine'
,'meta_query' => array(
         'key'     => 'vintage'
        ,'value'   => '2005'
        ,'compare' => '='

$query = query_posts( $args );

Querying the posts is a fine way to approach this problem. An alternate way of doing it is by setting up a custom taxonomy for fields with limited values. Vintage is a great choice for this, because you're only going to have so many years. The advantage of doing this with certain fields, is that you get list views, RSS feeds, permalinks, and the like "out of the box". Again, this won't work for every field, but it's likely that it's the best choice for the fields where you'll want to list by a specific value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.