Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
624 views
in Technique[技术] by (71.8m points)

wordpress custom post type pagination 404 page 2 error

In my Wordpress custom theme, a pagination giving the 404 error when loading the page above 1. I have checked out the Permalinks and other stuff but no scuccess.

Please help me to get rid off.

Here is my code.

//Loop
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

                 $args = array(
                     'orderby' => 'date',
                     'post_type' => 'jobs',
                     'posts_per_page' => 1,
                     'paged' => 'paged'
                 );
                 $the_query = new WP_Query( $args );

//Pagination
$total = $the_query->max_num_pages;
$big = 999999999; // need an unlikely integer
if( $total > 1 )  {
 if( !$current_page = get_query_var('paged') )
     $current_page = 1;
 if( get_option('permalink_structure') ) {
     $format = 'page/%#%/';
 } else {
     $format = '&paged=%#%';
 }
 echo paginate_links(array(
     'base'          => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
     'format'        => $format,
     'current'       => max( 1, get_query_var('paged') ),
     'total'         => $total,
     'mid_size'      => 3,
 ) );
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

please add this code to function.php file in your theme file

flush_rewrite_rules( false );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...