I have this code on a page called Categories.
<?php
/*
Template Name: Categories
*/
get_header(); ?>
<section id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<header class="page-header">
<h1 class="page-title">
Categories
</h1>
</header><!-- .page-header -->
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'posts_per_page' => '4',
'paged' => get_query_var('paged')
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php
get_template_part( 'content', 'categories' );
?>
<?php endwhile; ?>
<?php wp_pagenavi( array( 'query' => $the_query ) ); ?>
<?php wp_reset_query(); ?>
<?php endif; ?>
</main><!-- #main -->
</section><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I have set the template in admin to page-categories
The pagination shows up with the correct number of pages to browse, however, when I click on the next page (the link is something like example.com/categories/page/2/
) I get 404 page.
Why is that? how to fix it?