Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

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 );
share|improve this answer
1  
@Talbatz will want the compare to be '=' for his purposes (or leave it out, since its the default). –  Stephen Harris Jan 26 '12 at 11:13
    
Shouldn't the meta query be an array of arrays? codex.wordpress.org/Class_Reference/… –  Cristian Jan 26 '12 at 16:17

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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