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

The filter parameter does not work #1733

Closed

Description

@devotox

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

Activity

  1. danielbachhuber commented on Nov 13, 2015

    @danielbachhuber
    Member

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

  2. devotox commented on Nov 13, 2015

    @devotox
    Author

    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

  3. danielbachhuber commented on Nov 13, 2015

    @danielbachhuber
    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'] );

  4. devotox commented on Nov 13, 2015

    @devotox
    Author

    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).

  5. danielbachhuber commented on Nov 13, 2015

    @danielbachhuber
    Member

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

  6. devotox commented on Nov 13, 2015

    @devotox
    Author

    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).

  7. danielbachhuber commented on Nov 13, 2015

    @danielbachhuber
    Member

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

  8. devotox commented on Nov 13, 2015

    @devotox
    Author

    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).

  9. danielbachhuber commented on Nov 13, 2015

    @danielbachhuber
    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]

  10. devotox commented on Nov 13, 2015

    @devotox
    Author

    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).

  11. devotox commented on Nov 17, 2015

    @devotox
    Author

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions