#44326 closed enhancement (fixed)
Add relation parameter to REST API /wp/v2/posts endpoint
Reported by: | earnjam | Owned by: | earnjam |
---|---|---|---|
Milestone: | 5.4 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | has-unit-tests has-patch has-dev-note |
Focuses: | rest-api | Cc: |
Description
The REST API /wp/v2/posts
endpoint allows filtering by terms across multiple taxonomies, but it always uses an AND relationship between them.
Basically:
/wp/v2/posts?tags=1&categories=2
Translates to:
All posts with Tag 1 AND Category 2
WP_Query
supports passing a relation
parameter when running a tax query across multiple taxonomies. It defaults to AND, which is what we do now, but it would be nice to support the ability to specify OR here as well.
Attachments (2)
Change History (15)
This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.
5 years ago
#3
@
5 years ago
- Keywords needs-refresh added; has-patch removed
- Milestone changed from Awaiting Review to Future Release
This looks good to me!
I think we just need a different query parameter name that is a bit more specific to the term query. Perhaps terms_relation
?
#4
@
5 years ago
Thanks! I chose relation
since that was the name of the parameter in WP_Query
, though I can see how that is pretty vague. I like term_relation
, but I wonder if it should be something like tax_relation
since it's the relationship between the taxonomies, not the individual terms.
This ticket actually spun out of #41287, which is for supporting the use an AND
relationship between terms within a single taxonomy. I think the two would pair up nicely to extend what is possible through the API.
#7
@
5 years ago
- Keywords has-patch added; needs-refresh removed
44326.2.diff just updates the naming to tax_relation
This ticket was mentioned in Slack in #core-restapi by earnjam. View the logs.
5 years ago
#13
@
4 years ago
- Keywords has-dev-note added; needs-dev-note removed
This was detailed in the following dev note: https://make.wordpress.org/core/2020/02/29/rest-api-changes-in-5-4/
44326.diff:
/wp/v2/posts
endpoint calledrelation
which acceptsAND
orOR
. If left off, it defaults to the current functionality ofAND
.