Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress Rest API get total post count

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.

like image 639
krv Avatar asked Mar 23 '26 19:03

krv


1 Answers

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

like image 195
majman Avatar answered Mar 26 '26 13:03

majman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!