11

I am using the following to get posts

http://demo.wp-api.org/wp-json/wp/v2/posts

I the max limit on posts is 100 per request.

So I would have to make multiple requests to get all posts.

How can I get the total post count so I know how many requests I have to make?

Thanks.

2 Answers 2

27

The response headers include this data:

To determine how many pages of data are available, the API returns two header fields with every paginated response:

  • X-WP-Total: the total number of records in the collection
  • X-WP-TotalPages: the total number of pages encompassing all available records

By inspecting these header fields you can determine how much more data is available within the API.

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

also for reference: https://wordpress.stackexchange.com/a/250589

-2

Try this instead for pagination. It returns all the posts on my site.

http://example.com/wp-json/wp/v2/posts/?filter[posts_per_page]=10

filter[category_name]

http://example.com/wp-json/wp/v2/posts/?filter[category_name]=country&filter[posts_per_page]=111

Not the answer you're looking for? Browse other questions tagged or ask your own question.