How can I search it by metadata?
As far as I know, there’s no standard/built-in way of doing that (for the time being). But with custom coding, you can make it possible:
You can append a city
to the query string:
/wp-json/wp/v2/horario_busao?city=London
And then use the rest_{$this->post_type}_query
filter to set the meta key/value pair which would be passed to WP_Query
. Here’s an example:
add_filter( 'rest_horario_busao_query', function( $args, $request ){
if ( $city = $request->get_param( 'city' ) ) {
$args['meta_key'] = 'city';
$args['meta_value'] = $city;
}
return $args;
}, 10, 2 );