[wp-trac] [WordPress Trac] #52468: Filtering posts with multiple tags and tax relation AND returning unexpected results

WordPress Trac noreply at wordpress.org
Mon Feb 8 09:56:54 UTC 2021


#52468: Filtering posts with multiple tags and tax relation AND returning
unexpected results
--------------------------+-----------------------------
 Reporter:  milana_cap    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:
 Severity:  normal        |   Keywords:
  Focuses:  rest-api      |
--------------------------+-----------------------------
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52468>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list