airesvsg / acf-to-rest-api-recursive

Get ACF fields recursively
43 stars 8 forks source link

How do I filter by a property in an ACF group? #9

Open tristanisginger opened 3 years ago

tristanisginger commented 3 years ago

Hi

This plugin seems very neat but i'm having trouble find examples of what I want to achieve. Please can you point me in the right direction.

I'd like to filter all packages with a max price http://localhost/wp-json/acf/v3/packages?max_price=1001

The json is as follows

[{
      "id": 1,
      "acf": {
        "packages": {
          "title": "I am a doge",
          "price": "1000",
        }
      }
    }]

And my the code

add_filter( 'rest_query_vars', function ( $valid_vars ) {
    return array_merge( $valid_vars, array( 'max_price', 'meta_query' ) );
} );

add_filter( 'rest_packages_query', function( $args, $request ) {
// missing code
);