airesvsg / acf-to-rest-api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API
https://wordpress.org/plugins/acf-to-rest-api/
1.33k stars 111 forks source link

Filter ACF Custom Post Type CPT UI #326

Open luciobatistella opened 4 years ago

luciobatistella commented 4 years ago

Hello, I am using CPT UI to create my type posts. Even watching a video showing how to make the filter, mine did not work. I added the code in functions and I call it rest_post_query also for custom post?

`add_filter( 'rest_post_query', function( $args ) { $fields = array( 'tipo_cadastro' );

foreach ( $fields as $field ) {
    if ( isset( $_GET[ $field ] ) && ! empty( $_GET[ $field ] ) ) {
        $args['meta_query'][] = array(
            'key' => $field,
            'value' => esc_sql( $_GET[ $field ] ),
        );
    }
}

return $args;

} );`