Custom post type pagination 404 fix?

Been trying to get this working all day but haven’t had any luck…

I have a custom post type called ‘news’ and an archive template (archive-news.php), here I’d like to show 2 posts with pagination, which works fine, until I try to go to the ‘next page’ (/news/page/2) which returns an error 404.

Read More

Any idea how to fix this / what I’m doing wrong?

I’ve literally spent all day trying to find a solution to this by searching Google and the WordPress forms, I found lots of solutions, none of which have worked so far.

My custom post type function: http://pastebin.com/uG1L6YNu
My rewrite rules print: http://pastebin.com/jbaDANYr

Related posts

Leave a Reply

4 comments

  1. This is now working for me… for those of you having the same issue it turns out all the code was correct.

    The problem was WordPress is setup to show 10 posts per page by default which clashed with my query (limiting it to 2 posts) to fix the issue I changed the WordPress setting (Settings / Reading in the admin dashboard) to 1.

  2. You have probably tried this, but resetting the permalinks can solve this problem. Go to Settings->Permalinks and save the permalinks again.

  3. try this variant:

    add_action('pre_get_posts','custom_pre_get_posts'); 
    function custom_pre_get_posts( $query ) 
    {  
        if( $query->is_main_query() && !$query->is_feed() && !is_admin()) {
            $query->set( 'paged', str_replace( '/', '', get_query_var( 'page' ) ) );  
        }  
    } 
    
    add_filter('request', 'custom_request');
    function custom_request($query_string )
    { 
        if( isset( $query_string['page'] ) ) { 
            if( ''!=$query_string['page'] ) { 
                if( isset( $query_string['name'] ) ) { 
                    unset( $query_string['name'] ); 
                } 
            } 
        } return $query_string; 
    }