Add custom parameter to REST API request of a custom post type?
I registered a custom post type called wasb_message
with show_in_rest
set to true
and rest_base
set to 'messages'
so the resource is reachable at endpoint https://mydomain/wp-json/wp/v2/messages (using the WP_REST_Posts_Controller
class).
The custom post type has a custom meta field called wasb_status
with an integer value, how can I add a custom parameter so when I do a get request to endpoint https://mydomain/wp-json/wp/v2/messages?status=2 I retrieve messages with wasb_status
equal to 2 without register a new route?
I read this code reference page and this old question but I can't get it working, using Postman to send get request I get:
{
code: rest_invalid_param,
message: Parametro(i) non valido(i): status,
data: {
status: 400,
params: {
status: Stato non consentito.
},
details: {
status: {
code: rest_forbidden_status,
message: Stato non consentito.,
data: {
status: 401
}
}
}
}
}
Topic rest-api custom-post-types Wordpress parameter
Category Web