It looks like it's not supported, skimming through the docs
Here are some workarounds:
1) Custom modified_after
rest query parameter
We can add the modified_after
rest query parameter for the post
post type with:
add_filter( 'rest_post_collection_params', function( $query_params ) {
$query_params['modified_after'] = [
'description' => __( 'Limit response to posts published after a given ISO8601 compliant date.' ),
'type' => 'string',
'format' => 'date-time',
];
return $query_params;
} );
and then modify the rest post query accordingly with:
add_filter( 'rest_post_query', function( $args, $request ) {
if( isset( $request['modified_after'] ) && ! isset( $request['after'] ) ) {
$args['date_query'][0]['after'] = $request['modified_after'];
$args['date_query'][0]['column'] = 'post_modified';
}
return $args;
}, 10, 2 );
where we let after
take priority over modified_after
.
Example:
/wp-json/wp/v2/posts??modified_after=2017-11-07T00:00:00
Notes:
We might have used modified_gmt_after
for the post_modified_gmt
column.
It might be better to use a more unique name than modified_after
to avoid a possible future name collision.
To extend this to other post types, we can use the rest_{$post_type}_collection_params
and the rest_{$post_type}_query
filters.
Another option is to create a custom endpoint and parameters, that's a more work to do there. It's of course a question if we should add a custom parameter to the current rest api. In some cases it should be ok, as we're not removing or modifying the response, or changing how other parameters work.
2) Custom date_query_column
rest query parameter
Another approach would be to introduce a custom date_query_column
rest query parameter:
add_filter( 'rest_post_query', function( $args, $request ) {
if ( ! isset( $request['before'] ) && ! isset( $request['after'] ) )
return $args;
if( isset( $request['date_query_column'] ) )
$args['date_query'][0]['column'] = $request['date_query_column'];
return $args;
}, 10, 2 );
add_filter( 'rest_post_collection_params', function( $query_params ) {
$query_params['date_query_column'] = [
'description' => __( 'The date query column.' ),
'type' => 'string',
'enum' => [ 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt' ],
];
return $query_params;
} );
that would be available if either after
or before
parameters are set.
Example:
/wp-json/wp/v2/posts??after=2017-11-07T00:00:00&date_query_column=post_modified
Hope it helps!
add_filter
code here github.com/WP-API/rest-filter/blob/master/plugin.php#L18 after fork & using that updated plugin will work? – Untangle