Site icon Hip-Hop Website Design and Development

WordPress API response filter by ACF value

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?