wp-graphql / wp-graphql-tax-query

Adds `tax_query` support to postObject connection queries using WP_Query
46 stars 16 forks source link

Multiple Tax Query woes #15

Closed forepointmc closed 4 years ago

forepointmc commented 4 years ago

Hi I'm struggling to understand the results of this query.

I have a custom post type of food with three custom taxonomies veg, meat and fish:

query GET_FOOD(
  $first: Int
  $vegTerms: [String!]
  $meatTerms: [String!]
  $fishTerms: [String!]
) {
  food(
    first: $first
    where: {
      taxQuery: {
        relation: OR
        taxArray: [
          {
            terms: $vegTerms
            taxonomy: VEG
            operator: IN
            field: SLUG
          }
          {
            terms: $meatTerms
            taxonomy: MEAT
            operator: IN
            field: SLUG
          }
          {
            terms: $fishTerms
            taxonomy: FISH
            operator: IN
            field: SLUG
          }
        ]
      }
    }
  ) {
    edges {
      cursor
      node {
        id
        title
      }
    }
  }
}

/ Query Vars /

{
  "first": 1000,
  "vegTerms": ["apple", "pear"],
  "meatTerms": ["beef", "pork"],
  "fishTerms": ["cod", "haddock"]
}

Which returns no results.

If I take out any one of the taxonomies it returns the correct results, but doesnt seem to work for more than 2, which I don't understand, and they all work as single queries.

Am I missing something here?

daltonrooney commented 4 years ago

I just came across this issue as well. It's just a minor logic error, the attached pull request should fix it.