Restoring Filter Parameter for Post Endpoints in WP-API

In old WP, there used to be a way of adding a filter parameter on any post endpoint. The feature was removed for some reason.
I just came across a plugin that claims to restore it: rest-filter/plugin.php at 4e35ed526b6bd3e099e137780e8b216cdb50c9c4 · WP-API/rest-filter · GitHub
The issues seem to link to a fork that has itself been removed lol - - so I was wondering, if this can be implemented in ClassicPress, and if so, how?

Is this doable? I wouldn’t mind some functions.php hacks to get it working either. Thanks!

@timkaye @omukiguy I know you two do a lot of work with the API. Is this something you’ve done or know about?

1 Like

Honestly, I don’t really see the point of doing this. It’s far better to create a custom endpoint instead, and then you can add custom queries all you like. (I have one site in particular that does this a lot.) This way you have endpoints that won’t accidentally interfere with one another, and you can fine-tune the security much more easily too.


Do you mean something like this?

add_action( 'rest_api_init', function () {
  register_rest_route( 'myplugin/v1', '/author/(?P<id>\d+)', array(
    'methods' => 'GET',
    'callback' => 'my_awesome_func',
    'permission_callback' => '__return_true',
  ) );
} );

This still works in both WP and CP. You can make custom endpoints with your own parameter filters as well as Tim shares. Extending the REST API might be better that way to control the expected results.


Thanks for all the responses, everyone - - yes I guess using custom endpoints is the practical way to go about doing this :slight_smile: Thank you for the code examples!


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.