I have this code on a page called Categories.

Template Name: Categories

get_header(); ?>



        <header class="page-header">
                <h1 class="page-title">



        $args = array(
            'post_type' => 'post',
            'posts_per_page' => '4',
            'paged' => get_query_var('paged')
        $the_query = new WP_Query( $args ); ?>



                    get_template_part( 'content', 'categories' );

            <?php endwhile; ?>

            <?php wp_pagenavi( array( 'query' => $the_query ) ); ?>
            <?php wp_reset_query(); ?>

        <?php endif; ?>

    </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?


The problem was in the same name for category slug "categories" and the same for the custom page that was holding all categories with the same name "categories".

I have solved that by changing categories slug (in permalinks settings) to singular "category" and I have left custom page as plural "categories".

If somebody know about some better solution, please let me know, thanks.

P.S. I was thinking about deleting this question, however, I think thinks is an interesting problem and maybe somebody will find it helpful. But If any moderator think it's ot worth of sharing, you can delete this question.


This line:

            'paged' => get_query_var('paged')

Should be set to the $paged var you just set, like so:

            'paged' => $paged

Your Answer

