• I’m currently trying to query multiple meta_values under one meta_key – rating.

    At present my query is the following:

    <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('cat=18,42&meta_key=rating&meta_value=8&9&10'.'&paged='.$paged); ?>

    This only shows items with a meta_value of 8 though, not 8, 9, and 10 as I want it to. I’ve tried separating the values with commas however that doesn’t do anything either. Does anyone have any advice?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter sirgeordie

    (@sirgeordie)

    After much looking around, I’ve realised that this is what I need:

    <?php

    $querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wposts.ID = wpostmeta.post_id
    AND wpostmeta.meta_key = 'rating'
    AND wpostmeta.meta_value = '8'
    AND wposts.post_status = 'publish'
    AND wposts.post_type = 'post'
    ORDER BY wposts.post_date DESC
    ";

    $pageposts = $wpdb->get_results($querystr, OBJECT);

    ?>

    That’s pretty much sorted. All I want to do now is show posts with a rating of 8, 9, and 10 in the same list, instead of just 8. Anyone have any ideas?

    Thread Starter sirgeordie

    (@sirgeordie)

    Oh, and somehow figure out how to implement pagination into the query and only select posts from category 18 and 42.

    Anyone?

    na3s

    (@na3s)

    In response to your first post, it wasn’t working because you were using ‘&’ where you should ahve been using ‘,’

    like so:

    <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query(‘cat=18,42&meta_key=rating&meta_value=8,9,10′.’&paged=’.$paged); ?>

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Doesn’t matter, you can’t do that in a query. WordPress’ query system does not support multiple selection on the meta_values.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to query multiple meta values under one meta key’ is closed to new replies.