Retrieve posts by page in wp rest api
-
20-10-2020 - |
Question
I want to develop an app for my WordPress.org website. I am using wp rest api to receive post in json. My question is how do I retrieve posts page by page. For example if there are 50 posts I want to receive 1-10 then 11-20 and so on.
Solution
Well, you can add ?page={$page_number}
to the URL that you're requesting.
See, for example, http://demo.wp-api.org/wp-json/wp/v2/posts/?page=2.
It appears to split the posts into pages of 10.
Reference
- WP-API documentation (I found this in the docs for v1 of the API, but per the sample URL above, it works on v2 as well)
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange