wp-graphql / wp-graphql-tax-query

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

Using a taxonomy query doesn't set the request type properly in WP_Query #12

Closed mwidmann closed 1 year ago

mwidmann commented 5 years ago

When using a taxQuery in a query, the taxonomy relevant request type properties are not set correctly on WP_Query. So for example when querying a category $wp_query->is_category returns false even though it should be true. Or when combining a tag and category related query, e.g.

query THE_POSTS {
  posts(
    first: 10
    where: {
      taxQuery: {
        relation: OR,
        taxArray: [
          { taxonomy: CATEGORY, field: SLUG, terms: ["startseite", "kultur"] }
          { taxonomy: TAG, field: SLUG, terms: "bangladesch" }
        ]
      }
    }
  ) {
    pageInfo {
      hasNextPage
      endCursor
    }
    nodes {
      title
      postId
    }
  }
}

both $wp_query->is_tag and $wp_query->is_category should be true.

This was caused because the the taxonomy queries were nested inside an additional array in map_input_fields which caused the functionality in https://github.com/WordPress/WordPress/blob/32d761ce7dc8429f07469fde36e96830edca48f1/wp-includes/class-wp-query.php#L885 not to trigger.

The query worked fine though, but plugins relating on the request type failed.