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
A simpler way that comply with protocol is to collect all responses, in sequence, and perform single setState() call. As follows: (error handling omitted for readability)
componentDidMount(){
}
In WordPress 4.9.6, I had to use
rest_{$this->post_type}_query
It's really possible to get more then 100 posts or terms (tags, categories).
You should use
rest_{$this->post_type}_query
hook (for posts) orrest_{$this->taxonomy}_query
hook for terms.But you have to know, that it's impossible to pass a
per_page
arg in yourGET
request with more then 100 value.WP API
will throw an error immediately (the hook will not help):per_page must be between 1 (inclusive) and 100 (inclusive)
(with 400 http status).To get around this problem you should pass a
per page
value in anotherget
argument. And after this to trace this value in your hook.So the code is:
For posts
For terms
Of course, for this to work, you have to pass
s976_per_page
(with any value like 500, 99999) argument inGET
request.