Opened 4 years ago
Closed 4 years ago
#52468 closed defect (bug) (duplicate)
Filtering posts with multiple tags and tax relation AND returning unexpected results
Reported by: | milana_cap | 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_relation
is for eachtax_query
. A separatetax_query
is built for each taxonomy query parameter. Sotags
,tags_exclude
,categories
,categories_exclude
etc... would each be a separatetax_query
. You could then usetax_relation
to 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&&ID
works, but I wouldn't consider it an official API.