Is it possible to add the Gallery field to a post type, and having some way of adding a different id/name for each gallery?
Basically what I am trying to do is have a page with multiple posts on it. When you add a new post, it has the options of adding a title, description, featured image, and a gallery.
But right now, only the gallery of the last post shows up for every post, even though each post has a different gallery.
view example here: http://testing.pyrowebdesign.com/sandi/portfolio/
So is it possible to add some sort of a unique ID to accompany the gallery of each post?
Thanks in advance!
Can you please post a snippet of your code which is used to make the gallery?
Am I right in assuming this piece of code is within a loop which is rendering many posts on 1 page?
There should be no need for a ‘unique ID’ for each gallery, the get_field function can load from multiple posts on 1 page. Perhaps the $post object is not correctly setup in your loop?
Yes your assumption is correct. Sorry if i am not explaining this well.
Here is my code:
<!-- Main Content --> <div class="large-12 columns" role="content" style="margin-top: 2em;"> <?php while ($portfolio->have_posts()) : $portfolio->the_post(); ?> <?php $pagename = get_query_var('name'); ?> <div class="large-4 columns panel"> <h3><?php the_field('title'); ?></h3> <?php the_field('description'); ?> <a href="#" data-reveal-id="myModal"><?php the_post_thumbnail(); ?></a> </div> <div id="myModal" class="reveal-modal"> <?php $images = get_field('image_gallery'); if ( $images ): echo "<h3>".$images['id']."</h3>"; ?> <div class="flexslider"> <ul class="slides"> <?php foreach( $images as $image ): ?> <li><img src="<?php echo $image['url']; ?>" /></li> <?php endforeach; ?> </ul> </div> <?php endif; ?> </div> <?php endwhile; ?> </div> <!-- End Main Content -->
Basically I setup a while to check for the custom post type “portfolio” which in turn each post uses the ACF gallery field. I loop through and if there are posts, it posts them on the page. But for the gallery it seems to only do the last gallery of the most recent post, and it shows the same gallery for all the posts.
Thanks for the code, which looks fine to me.
The only issue I see is:
$images is an array and does not contain an ‘id’. Perhaps this is causing a PHP error? But even that would not change the results shown…
If you remove the flexslider classes and just output the images, Is the MARKUP correct?
Perhaps the issue is not with the PHP, but with some JS which is replacing the Markup?
You must be logged in to reply to this topic.
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!
Another heads up for next months #WPCafe. I hope you have been enjoying the monthly #WordPress chats we have been having with some great guests.— Mark Wilkinson (@wpmark) September 25, 2020
Next month is pricing WP products and services with @tom_hirst & @jackmcconnell
Watch previous episodes 👇https://t.co/IN2z2f0WSp
© 2020 Advanced Custom Fields. Subscribe