Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter by ACF Field Value #13

pakoArtal opened this issue Feb 26, 2016 · 6 comments

Filter by ACF Field Value #13

pakoArtal opened this issue Feb 26, 2016 · 6 comments


Copy link

@pakoArtal pakoArtal commented Feb 26, 2016

Hi Aires,

I'm trying to filter by ACF Field Value, just the same question asked for the previous version at airesvsg/acf-to-wp-rest-api#6.

Will your answer still work for this version? I tried your code but I'm not able to filter, getting all the results

I'm using:

  • WordPress 4.4.2
  • WP REST API Versión 2.0-beta12
  • Custom Post Type UI Versión 1.2.3 (Admin panel for creating custom post types and custom taxonomies in WordPress)
  • Advanced Custom Fields Versión 4.4.5
  • ACF to REST API Versión 2.0.6
Copy link

@airesvsg airesvsg commented Feb 26, 2016

Hi @pakoArtal,
If your Custom Post is "books", so your filter will be: rest_books_query = rest_{post_type}_query

add_filter( 'rest_query_vars', function ( $valid_vars ) {
    return array_merge( $valid_vars, array( 'land', 'meta_query' ) );
} );
add_filter( 'rest_books_query', function( $args, $request ) {
    $land   = $request->get_param( 'land' );

    if ( ! empty( $land ) ) {
        $args['meta_query'] = array(
                'key'     => 'land',
                'value'   => $land,
                'compare' => '=',

    return $args;
}, 10, 2 );


Copy link

@pakoArtal pakoArtal commented Feb 27, 2016

Hi @airesvsg ,

You were right. I forgot to change my filter to rest_books_query

Thank you for your help and for your plugin!

Copy link

@Idealien Idealien commented Jul 5, 2016

In that case, what would the end point be?
/wp-json/acf/v2/books?land=america ??

Nope - /wp-json/wp/v2/books?land=america


Copy link

@airesvsg airesvsg commented Jul 6, 2016

Hi @Idealien,
the endpoint /wp-json/acf/v2/books it is not supported in current version.
Please, see this issue: #51

Copy link

@Idealien Idealien commented Jul 6, 2016

Yeah; I edited trying to articulate that the /wp-json/wp/v2/books?land=america endpoint serves identical functionality for now. Either way, plugin is amazing and opening up so many front-end doors for development as ACF does to the admin side of WP.


Copy link

@honeyamin honeyamin commented Jun 10, 2018

what about using compare = IN
and also how can we use in loop?
if ( ! empty( $land ) ) { $args['meta_query'] = array( array( 'key' => 'land', 'value' => $land, 'compare' => 'IN', ) ); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants