The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Limit REST API Posts Per Page

Shared by Yusuf mudagal · May 3, 2026 · @rest_post_collection_params

79 views
Back to Snippets

Caps REST API post collection requests to a sensible maximum to avoid accidentally expensive API responses.

add_filter( 'rest_post_collection_params', 'wpfolks_limit_rest_posts_per_page' );

function wpfolks_limit_rest_posts_per_page( $params ) {
    if ( isset( $params['per_page']['maximum'] ) ) {
        $params['per_page']['maximum'] = 50;
    }

    return $params;
}
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments

Proudly supported by