Home › Forums › Add-ons › Repeater Field › Responsive images from repeater field › Reply To: Responsive images from repeater field
You need to have the setting of the field to return image or image IDs. See the image field documtation https://www.advancedcustomfields.com/resources/image/. Either that or your need to get the field unformatted and this will return the ID.
And that lead to the second part, you need to get the field using get_sub_field because ACF will not do this kind of formatting for you.
what you do next depends on what your returning.
If you’re returning an array then you need to get the values you want from that array. If your returning the ID then you need to get the values of the different image sizes yourself, honestly, I’d go with the array because there’s too much code to put it all here.
At any rate, you need to build the attributes for src and sizes yourself.
You’re other option is to create an image tag that looks identical to the image tag that WP inserts into the content area of a post and then
$image = 'construct your image tag'; $image = wp_make_content_images_responsive($image); echo $image;
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.