add_action('init',  function() {
    add_rewrite_rule('^foo', 'index.php?category_name=category1', 'top');

works and allows example.com/foo/ to display all the posts from category1.

But then the pagination doesn't work.

There is a link on the bottom of this page that shows "Older posts", and that redirects to example.com/foo/page/2/.

Question: how to have example.com/foo/page/2/ display all the posts from category1, page 2? (without a third party plugin)

1 Answer 1


Solved with:

add_rewrite_rule('^foo/page/([0-9]+)/?$', 'index.php?category_name=category1&paged=$matches[1]', 'top');    
add_rewrite_rule('^foo', 'index.php?category_name=category1', 'top');

The order between these two lines here is important.

See also Permalink/Pagination issue: Category base name same as page name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.