Pagination throws 404

Change predefined posts_per_page to minimum value in wordpress settings or add code below to functions.php. WordPress using default parameter. For example: 10. And if your settings in query_posts or WP_Query look like “posts_per_page=>2” and number of posts in custom post type less then 10, after clicking to /page/2/ you will redirected to page 404.

Use this code for functions.php for solve problem:

if( !is_admin() ){  
    add_action( 'pre_get_posts',  'set_per_page'  );
}
function set_per_page( $query ) {
    global $wp_the_query;
    if($query->is_post_type_archive('tutorial')&&($query === $wp_the_query)){
    $query->set( 'posts_per_page', 1);
    }
  return $query;
}

Leave a Comment