Wordpress - Filter out results from REST API

If you're using WP 4.7+ you can filter the query using the rest_$type_query hook wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:L267

This is a working example that filters current query by given terms

    $types = [
        'post',
        'page',
    ];

    foreach ( $types as $type ) {
        add_filter( 'rest_' . $type . '_query', 'filter_rest_query_by_zone', 2, 10 );
    }

    function filter_rest_query_by_zone( $args, $request ) {
            $zones = [ 'term1', 'term2', 'term3' ];

            $args['tax_query'] = array(
                'relation' => 'AND',
                array(
                    'taxonomy' => 'zones',
                    'field'    => 'term_id',
                    'terms'    => $zones
                )
            );

            return $args;
    }