Site icon Hip-Hop Website Design and Development

Pagination links for custom post type shows correct number of links, but links result in Page not found

This topic has many similar posts, but I’m not finding one that addresses my issue precisely.

Here is what I have done so far:

  1. I added a Custom Post Type to functions.php. This works. The imported posts show in the dashboard.

  2. I created a custom query to create a category page. This works, I can make it show a few or all of the records, but there are about a hundred posts in this category, so I need pagination.

  3. The pagination is producing the correct number of links, and the page addresses are incrementing accordingly.

Here is the code for the template:

<?php
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $args = array(
    'post_type' => 'lumber',
    'posts_per_page' => 12,
    'paged' => $paged
  );
  $LumberQuery = new WP_Query( $args ); 
?>

<?php 
  if ( $LumberQuery->have_posts() ) : 
    //  echo $LumberQuery -> post_count;
  ?>

    <?php 
      while ( $LumberQuery->have_posts() ) : $LumberQuery->the_post(); 
                echo '<div class="ProductListing">';
                echo '<a href="'.get_permalink().'">';
                the_post_thumbnail( 'thumbnail' );
                echo '</a>';
                the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );
                echo '</div><!-- End ProductListing div-->';
      endwhile; 
    ?>

    <div id="Pagination">
    <?php
      $big = 999999999; // need an unlikely integer
 
      echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $LumberQuery->max_num_pages
       ) );
    ?>
    </div><!-- end pagination -->
    <?php wp_reset_postdata(); ?>

<?php endif; ?>