How to get Media Field Value to display in frontend
Hi there,
I have used form_options to create form for custom widget in page builder using so widget bundle. Now I am able to get all the other field data like text, textarea, etc.
But I am not getting media URL that I have uploaded in MEDIA form field.
Can you please give me code to get my image that I have uploaded from media File upload?
Awaiting to hear from you.
This is our free support forum. Replies can take several days.
Need fast email support? Get SiteOrigin Premium
Replies
2Hi Makwana
Thanks for reaching out.
I had a quick chat with Braam, one of our developers. He let me know that the media field returns and ID, it doesn’t return a URL. You’ll need to use a function like:
https://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src
to resolve the URL.
Hope that helps a little. We unfortunately don’t have an example on GitHub, we just checked.
A quick addition. There are a few functions like the above. You can use any of them:
https://codex.wordpress.org/Function_Reference/wp_get_attachment_url
https://codex.wordpress.org/Function_Reference/wp_get_attachment_metadata
https://codex.wordpress.org/Function_Reference/wp_get_attachment_image
https://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src
https://codex.wordpress.org/Function_Reference/wp_get_attachment_link
https://codex.wordpress.org/Function_Reference/wp_get_attachment_thumb_url
Replies on this thread are closed.
Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.