Skip to content

Conversation

@kadamwhite
Copy link
Collaborator

This release resolves an issue with the query string formatting encountered when requesting posts of multiple types in the same query.

This release resolves an issue with the query string formatting encountered
when requesting posts of multiple types in the same query
@kadamwhite kadamwhite merged commit 40b8b29 into master Dec 4, 2014
@kadamwhite kadamwhite deleted the release-0.3.1 branch December 4, 2014 15:45
@kadamwhite kadamwhite restored the release-0.3.1 branch December 4, 2014 15:53
@kadamwhite kadamwhite deleted the release-0.3.1 branch December 4, 2014 15:53
kadamwhite added a commit that referenced this pull request Oct 5, 2016
This PR provides a convenience method for setting the `tax_query` filter:

```js
// Return only posts in category 29
site.posts().taxQuery({
  taxonomy: 'category',
  terms: [ 29 ]
})...
```

Note that if a relation is specified, numeric indices must be provided:

```js
// Return posts in (cats 49 or 29) && in tag 79 && NOT in tag 106
const request = site.posts().taxQuery({
  relation: 'AND',
  '0': {
    taxonomy: 'category',
    terms: [ 49, 29 ]
  },
  '1': {
    taxonomy: 'post_tag',
    // field: 'slug',
    terms: [ 79 ]
  },
  '2': {
    taxonomy: 'post_tag',
    terms: [ 106 ],
    operator: 'NOT IN'
  }
});
```

_If_ "OR" can be used as the topmost relation, an array of tax_query
objects can be provided to the filter method instead; however, any
nested queries must use array indices because the array -> object
parsing is not recursive.

```js
// Implicit OR: this query is, all posts with
// (tag #93 && category #49) || (tag #81 && not tag #116)
site.posts().taxQuery([{
  relation: 'AND',
  '0': {
    taxonomy: 'category',
    terms: [49]
  },
  '1': {
    taxonomy: 'post_tag',
    terms: [93]
  }
}, {
  relation: 'AND',
  '0': {
    taxonomy: 'post_tag',
    terms: [81]
  },
  '1': {
    taxonomy: 'post_tag',
    terms: 116,
    operator: 'NOT IN'
  }
}]);
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant