Support

Account

Home Forums Add-ons Gallery Field Get next/prev image url in gallery array Reply To: Get next/prev image url in gallery array

  • Hi @brotsky_pixie

    I’m not sure how your code works, but if you want to get the previous or the next image, you can use code like this:

    $images = get_field('gallery_field_name');
    if( $images ){
        foreach( $images as $key => $image ){
            if(isset($images[$key - 1])){
                echo "prev:" . $images[$key - 1]['url'];
            }
            echo $image['url'];
            if(isset($images[$key + 1])){
                echo "next:" . $images[$key + 1]['url'];
            }
        }
    }

    I hope this helps.