Opened 5 years ago
Closed 5 years ago
#52468 closed defect (bug) (duplicate)
Filtering posts with multiple tags and tax relation AND returning unexpected results
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | REST API | Keywords: | reporter-feedback |
| Focuses: | rest-api | Cc: |
Description
I've been trying to get posts from two tags (tax relation AND) with following arguments:
/wp-json/wp/v2/posts?tags=ID,ID&tax_relation=AND/wp-json/wp/v2/posts?tags=ID+ID&tax_relation=AND/wp-json/wp/v2/posts?tags[]=ID&tags[]=ID
None of these worked. They either returned on the first tag or all published posts.
Then I found this solution (by trial and error method):
/wp-json/wp/v2/posts?tags=ID&&ID
This one seems to work but only if the first ID is lower number.
I've tested this on several different WordPress installs (5.6 and 5.6.1) and all had the same results. You can quickly see it here:
This one doesn't work: https://make.wordpress.org/core/wp-json/wp/v2/posts?tags=3038&&1443
But this one works: https://make.wordpress.org/core/wp-json/wp/v2/posts?tags=1443&&3038
I haven't tested this with other taxonomies.
Change History (2)
Note: See
TracTickets for help on using
tickets.
Thanks for the ticket @milana_cap!
I believe this is expected behavior.
tax_relationis for eachtax_query. A separatetax_queryis built for each taxonomy query parameter. Sotags,tags_exclude,categories,categories_excludeetc... would each be a separatetax_query. You could then usetax_relationto say that the posts must have any of those tags, and any of those categories, etc...I think what you are looking for is #41287.
I'm not sure why
?tags=ID&&IDworks, but I wouldn't consider it an official API.