Skip to content

Conversation

@kadamwhite
Copy link
Collaborator

.id() is now used exclusively for setting the ID of a post.

@kadamwhite kadamwhite merged commit 7172ab0 into master Jun 29, 2014
@kadamwhite kadamwhite deleted the refactor/add-posts-comment-method branch June 30, 2014 06:34
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