This repository was archived by the owner on Sep 24, 2018. It is now read-only.
Add ?{taxonomy}_exclude= query parameter to posts
#2756
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_excludevariant to list IDs of terms for which associated posts should NOT be returned.For categories e.g.,
/wp/v2/posts?categories[]=7&categories[]=9would 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}_excludeis 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}_excludemaintains more consistency with other exclusion filters present in the API such asparent_exclude(and is much easier to implement, to boot).