-
Notifications
You must be signed in to change notification settings - Fork 2
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 #6
Comments
Hi @der-lukas, Register the queries vars: add_filter( 'rest_query_vars', function( $valid_vars ) {
return array_merge( $valid_vars, array( 'meta_query', 'meta_key', 'meta_value' ) );
} ); Adding parameters to filter: add_filter( 'rest_post_query', function( $args, $request ) {
$key = $request->get_param( 'meta_key' );
$value = $request->get_param( 'meta_value' );
if ( 'land' == $key && ! empty( $value ) ) {
$args['meta_query'] = array(
array(
'key' => $key,
'value' => $value,
'compare' => '=',
)
);
}
return $args;
}, 10, 2 ); Cheers |
Awesome! Thank you so much! |
@der-lukas if you want a most friendly url, like: add_filter( 'rest_query_vars', function ( $valid_vars ) {
return array_merge( $valid_vars, array( 'land', 'meta_query' ) );
} ); add_filter( 'rest_post_query', function( $args, $request ) {
$land = $request->get_param( 'land' );
if ( ! empty( $land ) ) {
$args['meta_query'] = array(
array(
'key' => 'land',
'value' => $land,
'compare' => '=',
)
);
}
return $args;
}, 10, 2 ); |
Oh, that's perfect! This way it's also possible to use multiple filters! :) Thanks! |
😄 👍 |
This is not working for multiple filters :( I'm trying to /wp-json/wp/v2/posts/?city=SP&state=SP Have tried duplicate the function also pass an array in multiple points of it, nothing have worked. :/ |
Hello @danilopaulinodasilva, I'm not give support for this version, please up to date for the most recent version in the link below. https://github.com/airesveg/acf-to-rest-api Thanks |
Hello, But...I'm using the last version (3.1.0) already? Oh, sorry I'm talking about this thread: airesvsg/acf-to-rest-api#123 I'll comment in the right place, sorry :) |
@airesvsg
Though, I added the filter in functions.php to filter by ACF field "country", doesn't work for me.
================================== |
same issue for me |
Hey! Thanks for this great plugin!
I already had a look at the other issues here, but still can't get it to work...
I want to get all the posts from the CPT "calendar" with a specific ACF-Field Value.
Would it be possible to request it like this:
".../wp-json/wp/v2/calendar/?meta_key=land&meta_value=de-AT"
Thanks in advance!
Lukas
The text was updated successfully, but these errors were encountered: