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'm trying to create a filter using two meta_values.

Example. If the current page has meta values red and blue, only display queried pages that have both red and blue and none that have just red or just blue.

I thought this could be accomplished with two meta values 'meta_value' => $red, $blue but apparently it's not available. Below is where I found myself before the block. I've done a ton of research and simply can't find a method that works. Any help would be appreciated.

$red = get_post_meta($post->ID, 'red', true);
$blue = get_post_meta($post->ID, 'blue', true);
$args = array(
'post_type' => page,
'nopaging' => true,
'post_parent' => 1440,
'meta_value' => $red, $blue
);

query_posts($args);
share|improve this question
    
I now see that this is a WordPress 3.1 feature. Is there currently a way to "fake" it. –  Zach Shallbetter Feb 18 '11 at 22:07
    
are you asking about two different custom fields? or one field with multiple values? –  Bainternet Feb 19 '11 at 1:07
    
Two different Custom fields. –  Zach Shallbetter Feb 19 '11 at 19:43
add comment

2 Answers 2

up vote 3 down vote accepted

'meta_query' is what you're looking for:

http://scribu.net/wordpress/advanced-metadata-queries.html

share|improve this answer
add comment

I think this should work if you wrap it in an array? Not entirely sure, though ... 'meta_value' => array('red', 'blue').

share|improve this answer
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. –  Brian Fegter Aug 27 '12 at 19:34
add comment

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.