Support

Account

Home Forums Add-ons Gallery Field Get the latest images from a gallery field? Reply To: Get the latest images from a gallery field?

  • sure. you need to count the images of the gallery, get the difference to 4, and loop through gallery but echo only the last 4 (the others loop without echo)

    something like this:

    $images = get_field('gallery');
    $count= count($images);
    if ($count > 4){
    $i = 0 - $count + 4;
    } else { $i=0;}
    foreach( $images as $image ): 
    $i++;
    if ($i > 0){
    echo $image['url'];
    }
    endforeach;

    not sure if code is correct, but it should help to made a correct one