Pagination gives 404 error

It’s seems that this bug of WP never was solved by WP team.

I have custom post-type, my url structure is /%category%/%postname%/ And if i click on 2nd page i will get 404 error.

Read More

I tried everything i found on internet, plugins, codes.. i even changed my pagination base url to NOT be page, so wp don’t think that i’m searching for post-type named page. But still nothing.

And yes i did the resave process of permalinks, i’ve tried restoring to deafault and then go back, still nothing…
Downloaded wp_navi still the same..

Is there anything i can do to solve this?

Related posts

Leave a Reply

1 comment

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