Modify WordPress Rest Api Request/Response

I think I found answer to your question, it is: rest_{$this->post_type}_query filter hook. With this hook you are able to directly edit internal WP_Query parameter.

For example, if you’d like to internally sort Posts by post_title by default, then you’d have to write something like this:

function order_rest_post_by_post_title($args, $request) {
  $args['orderby'] = 'post_title';
  $args['order'] = 'DESC';

  return $args;
}
add_filter('rest_post_query', 'order_rest_post_by_post_title', 10, 2);

For more info please follow this link.

Leave a Comment