How to fetch media files like images or videos from wordpress uploads?

Hi, I am very new to frontity or react, so this might come as a real noob question. Do I need to just copy and paste the media link or is there any special way of doing this like in PHP function wp_get_attachment_image()?

Hi @imrandev20, are you asking to fetch Featured Media? or please explain the question in a bit detail

No, not featured image. I was just trying to fetch a video file. I am trying to do a hero video background. Can video files be fetched using ID?

Yes, you can fetch any WordPress attachment or media in frontity by Rest API

Fetch media by ID

https://babacric.in/wp-json/wp/v2/media?id=13024

Fetch media by Post Id

https://babacric.in/wp-json/wp/v2/media?parent=13004

Hope this will help you :pray:

1 Like

Thank you for your response. Since I am hosting WordPress locally, the root address would change once I host it online. Wouldn’t that require me to update the REST API link everywhere as well?

If so, is there any way around this?

You can set the Rest API path to state that is in the index.js file.

So whenever you need to change the Rest API path you have to change only in the index.js file in the state.

You see a demo below

Inside state → theme → restApiPrefix

Hope this will work :grinning:

1 Like

Magnificent. Thank you.

1 Like