[wp-trac] [WordPress Trac] #41287: Getting posts that belong to multiple tags or categories

WordPress Trac noreply at wordpress.org
Mon Jul 10 22:33:31 UTC 2017


#41287: Getting posts that belong to multiple tags or categories
--------------------------+-----------------------------
 Reporter:  sebbb         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  4.8
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I'm trying to query the Rest API to get only posts that contain a given
 set of tags. If, for example, I request the following from the Rest API:

 `/wp-json/wp/v2/posts?tags=41+50`

 I get posts that don't satisfy all the tags. For example, the first post
 returned in the JSON response has the tags `45, 38, 46, 42, 35, 50, 43,
 36, 37, 75, 76`. The post doesn't have the tag with ID 41, while the
 expected output would be only posts that satisfy all the provided tags.

 It looks like behind the scenes the API uses an OR logic instead of the
 correct AND logic. It returns posts that contain at least one of the
 provided tags. I'm experiencing the same exact problem with categories as
 well.

 I tried different versions of the above URL, but I'm facing the same
 issue:

 `/wp-json/wp/v2/posts?tags=41&tags=50`

 `/wp-json/wp/v2/posts?tags=41,50`

 Interestingly, '''tags_exclude''' seems to work perfectly and the
 following url correctly returns posts that have neither the tag ID 41 nor
 the tag ID 50:

 `/wp-json/wp/v2/posts?tags_exclude=41+50`

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


More information about the wp-trac mailing list