WP API to fetch all the media/posts records if count is more than 100

Add a page number query to your request URL, and continue querying next page numbers until you get an empty result:

<your_wordpress_install_base_url>/wp-json/wp/v2/media/?per_page=100&page=2

Mark’s suggestion to consider requesting less than 100 per page may be a good one. So for example you may want to do your query this way:

<your_wordpress_install_base_url>/wp-json/wp/v2/media/?per_page=25&page=3

Note also that (for me at least) these query URLs work if constructed as just ~/media?per_page=3 (instead of ~/media/?per_page=3). I don’t know whether one or the other is preferred.

Thanks, incidentally, for the /media/?per_page=100 part of your example. I’d been stumped about getting empty results when querying just /media 🙂

Leave a Comment

error code: 523