I am surprised that no one mentioned using their own filters created by WordPress for such situations.
I managed to get the desired number of posts back by default, while allowing the $_GET['per_page'] parameter to work like this:
function setRestApiPostsPerPage($newDefault) { foreach (get_post_types() as $i => $postType) { add_filter( "rest_{$postType}_query", function ($args, $request) { if (! isset($_GET['per_page'])) {
I found that you cannot set $args['posts_per_page'] = -1; This results in an error that you can see here .
You can add any logic to the closure / callback / filter to set $args['posts_per_page'] as you would like.
source share