WordPress Rest API get total post count
Asked Answered
C

2

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.

Coolidge answered 29/1, 2018 at 14:21 Comment(0)
M
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

Maharani answered 13/2, 2018 at 14:25 Comment(0)
L
-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

Lancers answered 30/1, 2018 at 4:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.