media - Get all uploaded images using REST api

admin2025-01-07  3

I need to get all the images that are uploaded in my wordpress installation using the REST API. I've tried using the wp-json/wp/v2/media endpoint but it will give me only the last 10 images uploaded that are attached to the last published post but this isn't what I was expectinng.

How I can get all the images that are uploaded in wordpress unsing the rest api?

I need to get all the images that are uploaded in my wordpress installation using the REST API. I've tried using the wp-json/wp/v2/media endpoint but it will give me only the last 10 images uploaded that are attached to the last published post but this isn't what I was expectinng.

How I can get all the images that are uploaded in wordpress unsing the rest api?

Share Improve this question asked Sep 23, 2020 at 13:42 jimmy26jimmy26 111 silver badge2 bronze badges 4
  • 1 Do you just need to request more pages from the API? Look in the response headers: there should be two headers there with the max number of pages and total number of images. See developer.wordpress.org/rest-api/using-the-rest-api/pagination – Rup Commented Sep 23, 2020 at 14:41
  • I need to get all the media uploaded. I want to get at least 20 images because I will not query the api more than once, I'm working on a slideshow so I will not have pagination but only x images to display – jimmy26 Commented Sep 23, 2020 at 16:28
  • Try adding ?per_page=20 then, or another limit up to 100. But there's no reason you can't use the API more than once to build up a list in pages, either at the beginning or dynamically as they're needed. – Rup Commented Sep 23, 2020 at 16:29
  • @Rup solved,thanks for the help. I just need a single ajax call to fetch the images I need for the slider. it will be unuseful for my scope to make multiple ajax calls, it doesn't have any sense in a slider. – jimmy26 Commented Sep 23, 2020 at 16:53
Add a comment  | 

2 Answers 2

Reset to default 1

So the problem you are encountering is that you can not request all of them at once. Meaning you have to add a parameter to the request. Something like this:

/wp-json/wp/v2/media?per_page=100

If you have more than 100 images you have to paginate through the results, using the page parameter. Something like this:

/wp-json/wp/v2/media?per_page=100&page=1

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

If you need any further information, let me know!

add per_page: 100 as params also set page: 1 for first 100 and 2 for next 100

Have a look:- https://i.sstatic.net/Mbd5F.png

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736262066a790.html

最新回复(0)