• Resolved Mort

    (@rugbert)


    Say I wanted to filter posts not with one key and value, but a few of them, how would I go about doing that?

    query_posts(‘meta_key=color&meta_value=blue’); Just does one key and value, what if I wanted to filter by color AND shape?

    like:
    query_posts(‘meta_key=color&meta_value=blue’ AND ‘meta_key=shape&meta_value=triangle’ );

Viewing 4 replies - 1 through 4 (of 4 total)
  • MichaelH

    (@michaelh)

    You’ll need to use wpdb for that.

    See the example there:
    http://codex.wordpress.org/Function_Reference/wpdb_Class#Examples_4

    Thread Starter Mort

    (@rugbert)

    cooool. I just started learning SQL but Ive got enough down for my query…

    where do I put this part tho?:

    if ($postids) {
      echo 'List of ' . $meta_key3_value . '(s), sorted by ' . $meta_key1 . ', ' . $meta_key2;
      foreach ($postids as $id) {
        $post=get_post(intval($id));
        setup_postdata($post);?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      }
    }
    ?>

    in the loop?

    MichaelH

    (@michaelh)

    Actually that is ‘the loop’ replacement.

    Thread Starter Mort

    (@rugbert)

    AWESOME! Ok I almost have it. For some reason tho, I get no results when I add something like this

    AND post_id IN (SELECT post_id
    FROM wp_postmeta
    WHERE ( meta_key = ‘Utilities’
    AND meta_value = ‘%Water%’ ))

    works fine from terminal, but not from the code you linked me to. As long as thats not in there I get search results, but as soon as I add that line (or another for a different key/value) I get nothing even tho I know the entry exists.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘query_posts using multiple fields and values’ is closed to new replies.