• Resolved pealo86

    (@pealo86)


    Let’s say I have a statement such as

    query_posts('meta_key=flavour&meta_value=French');

    That will process the results of a form containing checkboxes. E.g., the user can select multiple values for flavour.

    Is there a way to have multiple values for ‘meta_value’. For example, for the statement to return true if the meta_value is either ‘French’, ‘German’ or ‘Spanish’.

    I was thinking of trying to get around it by creating the parameter string with a for loop, but I dont think that would work as all of the parameters would need to evaluate to true for the query to return anything back.

    Maybe I would just have to query every flavour and the simply remove those that I don’t need later on in the loop?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Use

    query_posts('meta_key=flavour');

    Then in your loop filter out what you want (or don’t want)

    $flavour = get_post_meta($post->ID, 'flavour', true);
    if (in_array($flavour, array('French', 'German', 'Spanish')) {
    echo 'Flavour is: '.$flavour';
    }

    Note: I believe in 3.1 there will be more powerful meta possibilities with query_posts.

    Thread Starter pealo86

    (@pealo86)

    Oh thanks, hadn’t thought of that!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Having an 'OR' statement in query_posts()’ is closed to new replies.