3

I have custom posts that represent real estate property and they have an ACF field of price. I'm trying to use the WP Rest API to query a certain price range, but to no avail.

E.g. querying the following URL returns all items rather than specific ones:

http://localhost/wp-json/wp/v2/property?filter[meta_query][relation]=AND&filter[meta_query][0][key]=price&filter[meta_query][0][value]=0&filter[meta_query][0][compare]=>&filter[meta_query][1][key]=price&filter[meta_query][1][value]=2681724&filter[meta_query][1][compare]=<

Even querying a specific price returns all items, e.g.:

http://localhost/wp-json/wp/v2/property?filter[meta_key]=price&filter[meta_value]=3000000

I've already added the relevant variables via the rest_query_vars filter:

function bones_allow_meta_query( $vars ) {    
    $vars[] = 'meta_key';
    $vars[] = 'meta_value';
    $vars[] = 'meta_query';

    return $vars;
}
add_filter( 'rest_query_vars', 'bones_allow_meta_query' );

It seems as though the filter query is completely ignored. What am I doing wrong?

1 Answer 1

1

Couldn't get it to work. The only solution that I found was to setup a custom endpoint:

http://v2.wp-api.org/extending/adding/

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.