[resolved] Having an 'OR' statement in query_posts() (3 posts)

  1. pealo86
    Posted 4 years ago #

    Let's say I have a statement such as


    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?

  2. MichaelH
    Posted 4 years ago #



    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.

  3. pealo86
    Posted 4 years ago #

    Oh thanks, hadn't thought of that!

Topic Closed

This topic has been closed to new replies.

About this Topic