I am missing the function to get ALL the posts (or CPT) by using
example.com/wp-json/wp/v2/country/?per_page=-1
or any similiar. The documentation gives as much info as this:
per_page: Maximum number of items to be returned in result set.
Default: 10
And in another question about the per_page we learn that the allowed range is 1 to 100.
In my case there will be a limited number of posts I need to get, but it will be around 200-300. Are there any workarounds to get them all other than fetching everything page per page and stitching it together?
Additional info if it does matter: I am using angular.js
Try this instead for pagination. It returns all the posts on my site.
http://example.com/wp-json/wp/v2/posts/?filter[category_name]=country&filter[posts_per_page]=-1
I get returns above 100 when entered like that and can cap them at 111 etc.
http://example.com/wp-json/wp/v2/posts/?filter[category_name]=country&filter[posts_per_page]=111
For the modern WP scenarios the following function will allow you to give returns great than 99.
add_filter( 'rest_post_collection_params', 'big_json_change_post_per_page', 10, 1 );
function big_json_change_post_per_page( $params ) {
if ( isset( $params['per_page'] ) ) {
$params['per_page']['maximum'] = 200;
}
return $params;
}
Couldn't get more than 10 with that syntax. Tried http://example.com/wp-json/wp/v2/posts?per_page=100
and worked up to 100.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With