Home › Forums › Pre-purchase Questions › Gallery add-on › Reply To: Gallery add-on
Hi @milanomia
I was unaware that you wanted to use a shortcode with the WP gallery. You will need to write something like this:
<?php
$images = get_field('gallery');
$image_ids = array();
$max = 4;
$i = 0;
if( $images )
{
foreach( $images as $image )
{
$i++;
if( $i > $max){ break; }
$image_ids[] = $image['id'];
}
}
$shortcode = '[gallery columns="1" link="file" size="medium" ids="' . implode(',', $image_ids) . '"]';
echo do_shortcode( $shortcode );
?>
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.