7

I searched this issue and tried several solution with no luck.

My main route is here: https://cnperformance.wpengine.com/wp-json/wp/v2/products?_embed

I installed the 'WP REST API filter parameter' plugin to restore filter removed when REST API moved to WordPress core.

I've tried: https://cnperformance.wpengine.com/wp-json/wp/v2/products?_embed&?filter[per_page]=-1

and

https://cnperformance.wpengine.com/wp-json/wp/v2/products?_embed&?filter[posts_per_page]=-1

I've also tried this in functions.php

add_filter( 'rest_endpoints', function( $endpoints ){
    if ( ! isset( $endpoints['/wp/v2/products'] ) ) {
        return $endpoints;
    }
    unset( $endpoints['/wp/v2/products'][0]['args']['per_page']['maximum'] );
    return $endpoints;
});

reference here: https://github.com/WP-API/WP-API/issues/2316

I've set the value of posts_per_page to 100, -1, didn't make a difference. I also tried just adding the parameters '&posts_per_page=-1 without the filter query and that didn't work either. Any help or insights greatly appreciated!

kurtg
  • 73
  • 1
  • 1
  • 5

3 Answers3

17

yes, you can fetch more then the default 10 posts at once.

just add the per_page parameter to your request.

example: https://cnperformance.wpengine.com/wp-json/wp/v2/products/?per_page=100

while 100 is the current max limit!

more info: https://developer.wordpress.org/rest-api/using-the-rest-api/pagination/


example how load more then 100 items at once

with a for loop and information of the total pages amount after your first request:

https://github.com/AndreKelling/mapple/blob/master/public/js/mapple-public.js#L46

André Kelling
  • 1,575
  • 16
  • 23
1

If per_page is not working, use filter[limit] for example

https://cnperformance.wpengine.com/wp-json/wp/v2/products/?filter[limit]=100
zawhtut
  • 8,335
  • 5
  • 52
  • 76
0

Addition to this article if you need to get more tham 100 articles at once, into file functions.php of the current wordpress theme add next code:

   add_filter('rest_post_collection_params', function ($params, $post_type) {
        if (isset($params['per_page'])) {
            $params['per_page']['maximum'] = 999;//edit it as you want
        }
    
        return $params;
    }, 10, 2);
realmag777
  • 2,050
  • 1
  • 24
  • 22