Support

Account

Home Forums Add-ons Gallery Field Add unique ID to gallery field, so it can be used as a separate post

Solving

Add unique ID to gallery field, so it can be used as a separate post

  • 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!

  • Hi @Pyromania666

    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?

    Thanks
    E

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

  • Hi @Pyromania666

    Thanks for the code, which looks fine to me.
    The only issue I see is:

    
    echo "<h3>".$images['id']."</h3>";
    

    $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?

    Thanks
    E

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Add unique ID to gallery field, so it can be used as a separate post’ is closed to new replies.