Sveltestorb70
Sveltestorb70

Reputation: 43

Rest API to get all media from Wordpress Site

I am trying to get all the media from my WordPress site: www.napkinsights.com through the use of a REST API. However, when I go to https://napkinsights.com/wp-json/wp/v2/media, all I receive is an empty array.

So I was wondering, how would I be able to access all the media from my website through an API Call?

Upvotes: 1

Views: 2452

Answers (1)

Pipo
Pipo

Reputation: 518

REST API will show only those uploaded directly to Media Libary, try it for your self and see it.

If you call media/id/ of the image you will get

{
"code": "rest_forbidden",
"message": "Sorry, you are not allowed to do that.",
"data": {
"status": 401
}
}

But If it's an image not attached to post and created directly at Media Libary It will display in REST API.

Your second best option is to directly access via SQL all those images

select * from wp_posts where post_type = 'attachment';

Upvotes: 2

Related Questions