Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Add ?{taxonomy}_exclude= query parameter to posts - #2756

#2756
Merged
joehoyle merged 1 commit into
developWP-API/WP-API:developfrom
support_taxonomy_term_exclusionWP-API/WP-API:support_taxonomy_term_exclusionCopy head branch name to clipboard
Oct 6, 2016
Merged

Add ?{taxonomy}_exclude= query parameter to posts#2756
joehoyle merged 1 commit into
developWP-API/WP-API:developfrom
support_taxonomy_term_exclusionWP-API/WP-API:support_taxonomy_term_exclusionCopy head branch name to clipboard

Conversation

@kadamwhite

Copy link
Copy Markdown
Contributor

This mirrors our existing support for ?{taxonomy}= filtering in the posts controller (which allows querying for only records with are associated with any of the provided term IDs for the specified taxonomy) by adding an equivalent _exclude variant to list IDs of terms for which associated posts should NOT be returned.

For categories e.g., /wp/v2/posts?categories[]=7&categories[]=9 would return a post in categories 7 or 9; this PR adds support for the inverse query ?categories_exclude[]=7&categories_exclude[]=9, meaning "only return posts that are associated with neither category 7 or category 9."

{term base}_exclude is supported for any taxonomy registered with the API, and is set within the same loop inside the controller as the existing term include parameters.

While using the existing categories filter with a negative number was considered (see slack discussion), {base}_exclude maintains more consistency with other exclusion filters present in the API such as parent_exclude (and is much easier to implement, to boot).

This mirrors our existing support for `?{taxonomy}=` filtering in the
posts controller (which allows querying for only records with are
associated with any of the provided term IDs for the specified taxonomy)
by adding an equivalent `_exclude` variant to list IDs of terms for which
associated posts should NOT be returned.

For categories _e.g._, `/wp/v2/posts?categories[]=7&categories[]=9` would
return a post in categories 7 _or_ 9; this PR adds support for the inverse
query `?categories_exclude[]=7&categories_exclude[]=9`, meaning "only
return posts that are associated with neither category 7 or category 9."

`{term base}_exclude` is supported for any taxonomy registered with the API,
and is set within the same loop inside the controller as the existing term
include parameters.

While using the existing categories filter with a negative number was
considered ([see slack discussion][slack-disc]), `{base}_exclude` maintains
more consistency with other exclusion filters present in the API such as
`parent_exclude` (and is much easier to implement, to boot).

[slack-disc]: https://wordpress.slack.com/archives/core-restapi/p1475525429004981
@kadamwhite

Copy link
Copy Markdown
Contributor Author

@WP-API/amigos #reviewmerge

@joehoyle
joehoyle merged commit 50b1f24 into develop Oct 6, 2016
@joehoyle
joehoyle deleted the support_taxonomy_term_exclusion branch October 6, 2016 17:57
@joehoyle joehoyle changed the title Add ?{taxonomy}_exclude= query parameter Add ?{taxonomy}_exclude= query parameter to posts Oct 6, 2016
@rachelbaker rachelbaker added this to the 2.0 Beta 15 milestone Oct 8, 2016
kadamwhite added a commit that referenced this pull request Oct 11, 2016
PR #2756 added an `_exclude` complement to every registered taxonomy
query parameter method, e.g. `categories_exclude`, to permit an
API consumer to list an array of term IDs with which returned posts
should NOT be associated. However, that PR omitted the important step
of registering the parameters on the schema! This PR does so.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.