I'm working with Wordpress, I have custom post type named "Offers", and i have fields with ACF, contract_type. I'm trying to filter Rest API Json output based on an ACF subfield
/wp-json/wp/v2/offre?contract_type=contractType1
I also tied to use the plugin "acf-to-rest-api" with this code snippet in my function.php, but it dosent work.
add_filter( 'rest_user_query', function( $args ) {
$fields = array( 'contract_type', 'city', 'title' );
foreach ( $fields as $field ) {
if ( isset( $_GET[ $field ] ) && ! empty( $_GET[ $field ] ) ) {
$args['meta_query'][] = array(
'key' => $field,
'value' => esc_sql( $_GET[ $field ] ),
);
}
}
return $args;
} );
Here is my Json response:
I would like to have all the offers whose contract_type is passed as a url parameter (like /wp-json/wp/v2/offre?contract_type=contractType1)
Thanks
