1

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);
3
  • I now see that this is a WordPress 3.1 feature. Is there currently a way to "fake" it. Feb 18, 2011 at 22:07
  • are you asking about two different custom fields? or one field with multiple values?
    – Bainternet
    Feb 19, 2011 at 1:07
  • Two different Custom fields. Feb 19, 2011 at 19:43

2 Answers 2

3

'meta_query' is what you're looking for:

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

0

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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