There seem to be countless custom query pagination questions on here, so glad to know I'm not the only one struggling with it. Have tried following the answers in those questions but so far no luck.
I have a custom post type, say Galleries. Each post has a title, and an Advanced Custom Field Gallery field that includes images. When on one of those posts currently it shows the linked titles for the first 12 posts to the right of the images. This means you never get to see past the 12th. I could change the 12 to -1 to show all, but list would go on for a while.
Hoping to add pagination, so if you are on the first post, under the list on the right would said, "more" and would take you to the 13th post, and the list on the right would now show linked titles for 13 to 24. And there would be a prev button and a more button. Prev would go back to first page and show 1 12 titles, and more would take you to 25th post and show 25 to 36 and so on.
I've tried adding pagination in various way to accomplish that but with no luck. Some questions I thought looked right but gave errors. Is pagination the right way, or should I be developing a custom if else statements or such to accomplish this?
<?php get_header(); ?> <div id="main"> <div id="gallery-viewer"> <h3><?php the_title(); ?></h3> <?php $images = get_field('gallery_images'); if( $images ): ?> <ul class="thumbs"> <?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 class="places"> <ul class="plist selected first"> <?php $custom_query = new WP_Query( array( 'post_type' => 'customers_gallery', 'posts_per_page' => 12, 'paged' => $paged ) ); 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; ?> <?php endif; wp_reset_query(); ?> </ul> // Add Pagination </div> </div> </div><!-- /#main --> <?php get_footer(); ?>