• Hi, I am pulling my hair out trying to figure this out: I want to construct a query that will return posts whose meta values match an array of possibilities. Here is what I have been trying:

    $people_query = new WP_Query(‘category_name=who-we-are&meta_key=first_name&array(“meta_value”=> array(“john”,”sam”))&orderby=title&order=ASC’);

    but to no avail. I have tried various combos of quotes, tried adding “__and” to “meta_value” to simulate multiple category array, among other things. The query returns the full list of everyone in the category, no matter what I do. I only want it to return the list of people whose names match those in the array.

    Any ideas?

Viewing 1 replies (of 1 total)
  • Give this a try:

    function mam_posts_where ($where) {
       global $mam_global_where;
       if ($mam_global_where) $where .= " $mam_global_where";
       return $where;
    }
    add_filter('posts_where','mam_posts_where');
    $mam_global_where = " AND $wpdb->postmeta.meta_value IN ('john','sam')";
    $people_query = new WP_Query('category_name=who-we-are&meta_key=first_name&orderby=title&order=ASC');
Viewing 1 replies (of 1 total)
  • The topic ‘query posts with array of possible meta data values?’ is closed to new replies.