Pagination gives 404 error

Have you tried this?

I had gotten the same problem before. I did these steps, and it works for me.

I use this code in my functions.php

// New method of WordPress Query since 3.4.1
if ( ! function_exists( 'ucc_add_cpts_to_pre_get_posts' ) ) {
    function ucc_add_cpts_to_pre_get_posts( $query ) {
    if ( $query->is_main_query() && ! is_post_type_archive() && ! is_archive() && ! is_search() && ! is_singular() && ! is_404() ) {
        $my_post_type = get_query_var( 'post_type' );
        if ( empty( $my_post_type ) ) {
            $query->set('post_type', 'your_post_type_name'); // replace your_post_type_name with yours
        }
    }
}
}add_action( 'pre_get_posts', 'ucc_add_cpts_to_pre_get_posts' );

Then, I use this in my single-{post-type}.php

<?php $paged = 1;
  if ( get_query_var('paged') ) $paged = get_query_var('paged');
  if ( get_query_var('page') ) $paged = get_query_var('page'); 
  if (have_posts()): 
?>


<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $loop = new WP_Query( array(
    'post_type' => 'your_post_type_name', // replace your_post_type_name with yours
    'posts_per_page' => PER_PAGE_DEFAULT, // Displaying number posts per page equals to Reading Settings in WP admin
    'paged'=>$paged
  )); 
?>

<?php query_posts( '&post_type=your_post_type_name&paged=' . $paged );  ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

  <!-- The content is here -->

<?php endwhile; else: ?>
  <p>Not Found</p>
<?php endif; wp_reset_query(); ?>

<div class="navigation">
 <?php if(function_exists('wp_page_numbers')) { wp_page_numbers(); } ?> 
</div>

In my case, I use wp page numbers plugin.

Hopefuly, it can solve your problem.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)