Home › Forums › General Issues › image field as a loop function › Reply To: image field as a loop function
Hey @johnykalesony,
It’s not the most descriptive question so there’s some guesswork on my part. I’m assuming your image field is returning an array as opposed to an ID or a URL.
function my_custom_gallery() {
query_posts(array(
'post_type' => 'galeria',
'orderby' => 'publish_date',
'order' => 'ASC'
));
while (have_posts()) : the_post();
$image_field = get_field('image_field');
$image_url = $image_field['url'];
$image_alt = $image_field['alt']; ?>
<img src="<?php echo esc_url($image_url); ?>" alt="<?php echo esc_attr($image_alt); ?>" />
<?php endwhile;
}
add_shortcode('mygallery-1', 'my_custom_gallery');
I hope this helps!
Dan
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.