Skip to content
Advertisement

Why pagination is not working and gives a 404 error on the wordpress site?

Good day! The problem is this: in the template category(the archive) the pagination is not working, when you click on page 2 of the 404 error. Please help do not understand how to solve it, already all head broke

My loop:

JavaScript

And my custom pagination:

JavaScript

Advertisement

Answer

Since this has come up in two different forums lately, I am answering this.

If you use custom pagination, such as the one you’re using which appears to come from http://callmenick.com/post/custom-wordpress-loop-with-pagination but it happens with Genesis child themes too because the parent numbered pagination is what people what.

Why do you get a 404 page? The Custom pagination in the callmenick.com and Genesis (genesis_posts_nav) is for the main query and so if your pagination for your different query is under the posts per page in your reading settings (which is set for the main query), then you will get a 404 on page 2.

Every front end page request on a WordPress site produces a main query. The template that WordPress decides to load is based on the results of that main query (you can see the order that WordPress does these things by looking at the Action Reference page). Despite the fact that you never output the results of that query, it’s still run, and in the case of paginated archives, this is an issue if you’re trying to use that pagination for a different query. — Milo https://wordpress.stackexchange.com/a/120963/64742

You don’t see this question a lot because many just build the pagination for that loop instead of re-using it from the functions.php file or a parent theme. You can learn that here: https://codex.wordpress.org/Function_Reference/paginate_links

Let’s start from the top and whenever you code, turn on debug in wp-config.php


A basic custom loop in my cpt archive.

archive-product.php

JavaScript

In your functions.php file:

Learn about conditionals. https://codex.wordpress.org/Conditional_Tags https://codex.wordpress.org/Function_Reference/is_post_type_archive

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement