Have a custom post type, where each post is a gallery, and each has an Advanced Custom Fields Gallery field that has say 5-20 images each. Also have a custom post type post template as seen below (stripped out most of the code to focus on parts that are relevant to this.) The comments in the code explain which each part does. Overall it appears to all work, however no matter what post I'm on in this custom post type, such as example.com/gallery/gallery-1, example.com/gallery/gallery-2, example.com/gallery/gallery-3, etc. It shows the same featured image and same thumbnails on each page. It appears to be pulling the first gallery from the first post, rather than on each page checking to pull in the gallery items associated with that page.
I'm sure it's simple such as a matter of needing to flush/reset a loop or such, but struggling to find the right way to describe it to find the answer on Google. Had it working originally, but once I had to add loops inside of loops the issue started. If anyone has any idea would great. Will keep researching in the meantime.
<?php get_header(); ?>
<div id="main">
<?php
//Checks gallery custom post type and finds the current pages entry
$args = array( 'post_type' => 'customers_gallery', 'posts_per_page' => 1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div>
<?php
//Looks up the advanced custom field gallery associated with this post
$hero = get_field('gallery_images'); ?>
<!-- //Show the first image in that gallery -->
<img src="<?php echo $hero[0]['url']; ?>" class="main-image" style="width: 484px;">
<!-- //Shows title of this page -->
<h3><?php the_title(); ?></h3>
<?php
//Looks up the advanced custom field gallery associated with this post
$images = get_field('gallery_images');
//Loops through all the gallery image showing a thumbnail for each and each is linked to its full size
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<a href="<?php echo $image['url']; ?>">
<img src="<?php echo $image['sizes']['gallery-landscape-thb']; ?>" alt="<?php echo $image['alt']; ?>" />
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<div>
<ul>
<?php
//Looks up all the pages in this custom post type and lists the titles of the first 12 and linked to respective pages
$custom_query = new WP_Query(
array(
'post_type' => 'customers_gallery',
'posts_per_page' => 12
)
);
if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; wp_reset_query(); ?>
</ul>
</div>
</div>
<?php endwhile; ?>
</div>
<!-- /#main -->
<?php get_footer(); ?>
UPDATE
Some have noted to add a reset, but I'm still thinking the issue is something else. Since I can remove nearly all the code in template and get it down just to the following and it still echos the same title no mater which post im viewing in the gallery custom post type (it shows the first title in the list of posts in the gallery custom post type, where is it should pull in the title for that particular page. The title in the tab is correct.
<?php get_header(); ?>
<?php
$args = array( 'post_type' => 'customers_gallery', 'posts_per_page' => 1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php echo the_title(); ?>
<?php endwhile; ?>
<?php get_footer(); ?>
UPDATE 2
Returned to the original code that I posted in this message and simply removed the code noted in my second post aka, that $args = array( 'post_type' => 'customers_gallery'... and all works. So seems the issue was I was trying to create a loop for the custom post type but looks like that is not needed when using a single-[custom-post-type-name].php.