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
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.