REST API & Developer PHP Intermediate

Allow More Than 100 Items per REST Request

Raise the REST API's 100-item limit for one post type, so a script or app can fetch more items in a single request.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 6 lines
add_filter( 'rest_post_collection_params', function ( array $params ): array {
	if ( isset( $params['per_page'] ) ) {
		$params['per_page']['maximum'] = 250;
	}
	return $params;
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

The REST API returns at most 100 items per page. For exports, sync scripts or static site builds, paging through hundreds of requests is slow. This snippet raises the limit for posts.

How it works

Every collection endpoint defines its query parameters, including per_page with a maximum of 100. The rest_post_collection_params filter changes that maximum for posts. Requests with ?per_page=250 then work instead of returning an error.

Things to watch

  • Big pages use more memory and take longer to build. Raise the number gradually and test.
  • The filter name includes the post type: rest_page_collection_params for pages, rest_product_collection_params for a product post type.
  • Paging with X-WP-TotalPages is usually the better long-term solution.

How to test it

Request /wp-json/wp/v2/posts?per_page=250. It should return posts instead of a “per_page must be between 1 (inclusive) and 100” error.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only