I have an API call from Vue, that makes paginating of WordPress posts, the number of pages and offset work perfectly, I can make first page, previous and next page queries work perfectly with the offset parameter
https://example-page.com/wp-json/wp/v2/posts?categories=5&per_page=12&offset=12
But, for the last page I don’t know what should be the offset, if the number of posts change. How can I find out this number, which is the last page in the list?
2
Answers
You can get it in the header response with this code:
You can retrieve the total number of pages from the
X-WP-Total
response header.From that you can compute an offset for the last page.