I'm building a site with wordpress API. I'm using Advanced Custom Fields, and also ACF to Rest API plugin to expose ACF data in API: https://github.com/airesvsg/acf-to-rest-api

Now I'm trying to filter the response by ACF values. I was able to find this piece of code that helps with that:

add_filter( 'rest_product_query', function( $args ) {

    $ignore = array('per_page', 'search', 'order', 'orderby', 'slug');

    foreach ( $_GET as $key => $value ) {
      if (!in_array($key, $ignore)) {
        $args['meta_query'][] = array(
          'key'   => $key,
          'value' => $value,

    return $args;

Now I'm able to filter queries like so: https://example.com/wp-json/wp/v2/product?length=Customizable

The problem with this is that, now I'm not able to access api pages like https://example.com/wp-json/wp/v2/product?page=2, which I need to be able to do.

Any way to refactor this to still be able to use default wordpress API filters/search behavior?

Or, any alternative better way to do the same thing?

1 Answer 1


OK, I realized I should just add every default WP key it to the $ignore array, like this, I added 'page':

$ignore = array('page', 'per_page', 'search', 'order', 'orderby', 'slug');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.