Skip to content
This repository has been archived by the owner on Sep 24, 2018. It is now read-only.

The filter parameter does not work #1733

Closed
devotox opened this issue Nov 13, 2015 · 11 comments
Closed

The filter parameter does not work #1733

devotox opened this issue Nov 13, 2015 · 11 comments
Labels

Comments

@devotox
Copy link

devotox commented Nov 13, 2015

It seems to not actually filter any posts and also it then causes the page and per_page parameters to no longer work when the filter parameter is present in the url

@danielbachhuber
Copy link
Member

Can you share the request you're making, the version of the plugin you're using, and the actual result you see?

@devotox
Copy link
Author

devotox commented Nov 13, 2015

http://doctifyblog.com/wp-json/wp/v2/posts?page=1&per_page=1&filter=blah

I am on the latest beta and hitten the link will show you the actual result

@danielbachhuber
Copy link
Member

I am on the latest beta

Do you have any PHP filters that are modifying the request, by chance?

filter works as expected for me locally:

local ➜  wp-api git:(develop) http wordpress-develop.dev/wp-json/wp/v2/posts | jq '.[].id'
100
99
98
97
96
95
94
93
92
91
local ➜  wp-api git:(develop) http wordpress-develop.dev/wp-json/wp/v2/posts per_page==1 | jq '.[].id'
100
local ➜  wp-api git:(develop) http wordpress-develop.dev/wp-json/wp/v2/posts per_page==1 filter\[posts_per_page\]==2 | jq '.[].id'
100
99
local ➜  wp-api git:(develop) http wordpress-develop.dev/wp-json/wp/v2/posts per_page==1 page==2 filter\[posts_per_page\]==2 | jq '.[].id'
98
97

filter will override per_page and page if filter[posts_per_page] or filter[paged] are provided

$args = array_merge( $args, $request['filter'] );

@devotox
Copy link
Author

devotox commented Nov 13, 2015

Could you give me an example of how you would pass the filter as part of
the request. Is it just a string as a query parameter?
On 13 Nov 2015 5:54 p.m., "Daniel Bachhuber" notifications@github.com
wrote:

I am on the latest beta

Do you have any PHP filters that are modifying the request, by chance?

filter works as expected for me locally:

local ➜ wp-api git:(develop) http wordpress-develop.dev/wp-json/wp/v2/posts | jq '.[].id'
100
99
98
97
96
95
94
93
92
91
local ➜ wp-api git:(develop) http wordpress-develop.dev/wp-json/wp/v2/posts per_page==1 | jq '.[].id'
100
local ➜ wp-api git:(develop) http wordpress-develop.dev/wp-json/wp/v2/posts per_page==1 filter[posts_per_page]==2 | jq '.[].id'
100
99
local ➜ wp-api git:(develop) http wordpress-develop.dev/wp-json/wp/v2/posts per_page==1 page==2 filter[posts_per_page]==2 | jq '.[].id'
98
97

filter will override per_page and page if filter[posts_per_page] or
filter[paged] are provided

$args = array_merge( $args, $request['filter'] );


Reply to this email directly or view it on GitHub
#1733 (comment).

@danielbachhuber
Copy link
Member

GET http://wordpress-develop.dev/wp-json/wp/v2/posts?per_page=1&filter[posts_per_page]=2

@devotox
Copy link
Author

devotox commented Nov 13, 2015

Thank you but how would you actually search the text of each post and only
return matches based on the search parameter
On 13 Nov 2015 5:58 p.m., "Daniel Bachhuber" notifications@github.com
wrote:

GET
http://wordpress-develop.dev/wp-json/wp/v2/posts?per_page=1&filter[posts_per_page]=2


Reply to this email directly or view it on GitHub
#1733 (comment).

@danielbachhuber
Copy link
Member

GET http://wordpress-develop.dev/wp-json/wp/v2/posts?filter[s]=search+string

@devotox
Copy link
Author

devotox commented Nov 13, 2015

Yes if you see from the URL I sent you I tried exactly this with
filter=search string and I just got returned the first ten posts no matter
the filter passed in
On 13 Nov 2015 6:06 p.m., "Daniel Bachhuber" notifications@github.com
wrote:

GET
http://wordpress-develop.dev/wp-json/wp/v2/posts?filter[s]=search+string


Reply to this email directly or view it on GitHub
#1733 (comment).

@danielbachhuber
Copy link
Member

Yes if you see from the URL I sent you I tried exactly this with
filter=search string

You shared:

http://doctifyblog.com/wp-json/wp/v2/posts?page=1&per_page=1&filter=blah

To search for "blah", the proper request would be:

http://doctifyblog.com/wp-json/wp/v2/posts?page=1&per_page=1&filter[s]=blah

Notice filter[s]

@devotox
Copy link
Author

devotox commented Nov 13, 2015

Haaaaa thank you I thought the use of the [s] meant the parameter could
either be filter OR filters! Thanks for clearing that up and all your help
today
On 13 Nov 2015 6:14 p.m., "Daniel Bachhuber" notifications@github.com
wrote:

Yes if you see from the URL I sent you I tried exactly this with
filter=search string

You shared:

http://doctifyblog.com/wp-json/wp/v2/posts?page=1&per_page=1&filter=blah

To search for "blah", the proper request would be:

http://doctifyblog.com/wp-json/wp/v2/posts?page=1&per_page=1&filter[s]=blah

Notice filter[s]


Reply to this email directly or view it on GitHub
#1733 (comment).

@devotox
Copy link
Author

devotox commented Nov 17, 2015

That worked perfectly.
A couple of other questions now

  1. Is it possible to filter by things like top articles / categories
  2. Is it possible to filter by any generic metadata

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants