I have created an opps
custom post type and registered a custom API field of closed
for it with the following code:
public function get_opp_state() {
register_rest_field( 'opps', 'closed', array(
'get_callback' => array( $this, 'get_opp_state_callback' ),
'update_callback' => null,
'schema' => null
));
}
public function get_opp_state_callback( $opp ) {
$oppDeadline = get_field( 'deadline', $opp[ 'id' ] );
$today = date( 'Ymd' );
$isClosed = $oppDeadline < $today;
return $isClosed;
}
To retrieve all posts that use the opps
post type, I use this request:
http://example.com/wp-json/wp/v2/opps
Now how can I extend that request to only fetch opps
posts that have a closed
field equal to true? I was hoping the following would work, but it doesn’t:
http://example.com/wp-json/wp/v2/opps?closed=true
I know I can create a custom route, but I really would like to avoid that since the information returned by the default request has all the info I need (except for that closed
field). So is there any way to achieve this without a custom route?