[wp-trac] [WordPress Trac] #41908: REST API gives wrong output when filtering posts with multiple category IDs - issue with AND operator
WordPress Trac
noreply at wordpress.org
Mon Sep 18 11:15:52 UTC 2017
#41908: REST API gives wrong output when filtering posts with multiple category IDs
- issue with AND operator
------------------------------+-----------------------------
Reporter: subrataemfluence | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 4.8.1
Severity: normal | Keywords:
Focuses: rest-api |
------------------------------+-----------------------------
Encountered an issue while working with REST API which I am trying to
explain below with test cases:
Requirement:
'''Filter out posts which are associated with category ids 2, 4 AND 3.'''
REST API calls made:
{{{
http://example.com/wp-
json/wp/v2/posts?filter[category__in][]=2&filter[category__in][]=3&filter[category__in][]=4
}}}
The above call fetched all available posts. Then I tried this:
{{{
http://example.com/wp-
json/wp/v2/posts?categories=2&categories=4&categories=3
}}}
A better response this time, however, all posts having '''Category ID 3'''
(the last one in the list) are returned even some of them don't have
category ID 2 or 3 and some of have another category ID along with 3. In
short this call gave me posts like this:
'''Post A: 3, 9
Post B: 3
Post C: 3, 8, 12
Post D: 2, 3, 6
Post E: 2, 3, 4'''
When I am expecting only '''Post E''' to come up.
This time I changed the call a bit by putting the IDs in order:
{{{
http://example.com/wp-
json/wp/v2/posts?categories=2&categories=3&categories=4
}}}
I got the correct result, i.e. only Post E came up this time.
To extend my test a bit further I edited the post (Post E), removed
Category ID 2 from it and then tried the same call again. '''This time I
did not expect any result to come up because I am searching for posts
associated with Category IDs 2, 3 AND 4'''. But I still get Post E even it
is not associated with Category ID 2 anymore.
Its a clean WP install, no plugin is there yet.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41908>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list