Category template with pagination returns 404 on next pages

I am making a category template page with pagination and below is my code:

$current_page = get_queried_object();
$category = $current_page->slug;

$paged = get_query_var( ‘paged’ ) ? get_query_var( ‘paged’ ) : 1;
$query = new WP_Query(
‘paged’ => $paged,
‘category_name’ => $category,
‘order’ => ‘asc’,
‘post_type’ => ‘page’,
‘post_status’ => array(‘publish’),
‘posts_per_page’ => 6,
‘post_parent’ => 2,

if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post(); ?>

<article id=”post-<?php the_ID(); ?>”>
<header class=”entry-header”>
<?php the_title( sprintf( ‘<h2 class=”entry-title”><a href=”%s” rel=”bookmark”>’, esc_url( get_permalink() ) ), ‘</a></h2>’ ); ?>
</header><!– .entry-header –>

<div class=”entry-content”>
<?php the_content(); ?>
</div><!– .entry-content –>
</article><!– #post-## –><hr>


// next_posts_link() usage with max_num_pages
next_posts_link( ‘Older Entries’, $query->max_num_pages );
previous_posts_link( ‘Newer Entries’ );


So I have about 10 pages with the same category (e.g. arts).

And I will get the next page link from next_posts_link( ‘Older Entries’, $query->max_num_pages );. It generates link like this:

But I get a 404 page when I click on this url above. It should stays at the category template, shouldn’t it?

So I added the following fix into functions.php:

add_action( ‘init’, ‘wpa58471_category_base’ );
function wpa58471_category_base() {
// Remember to flush the rules once manually after you added this code!
// The regex to match the incoming URL
// The resulting internal URL
// Add the rule to the top of the rewrite list
‘top’ );

But I still get the 404 page. What have I done wrong?

Any ideas?

Read more here:: Category template with pagination returns 404 on next pages

Leave a Reply

Your email address will not be published. Required fields are marked *