Support

Account

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