Skip to content
Advertisement

Page displaying a specific category has pagination problem

I have a client that has a Static WordPress website with a blog.

The main blog page (home.php) works great with pagination all correct.

Note: I am using the WP-PageNavi to do the pagination for me.

I have also created a customized template page that displays the posts from a specific category (recipes). The pagination code doesn’t work correctly on this page. There should be two pages available, and it only shows that there is one.

I know the issue is that I need to tweak the coding for the pagination on the recipe page, but I don’t really know what to do.

This is the recipe (category) blog page link: www.aphrodisiacsexpert.com/aphrodisiacs-expert-blog/aphrodisiac-recipes/

Here is the code that displays the page with the recipes blog posts along with its pagination:

JavaScript

Can anyone give me some ideas on how to fix this problem?

Thanks, SunnyOz

Advertisement

Answer

After many hours of researching, I finally found one question similar to mine (from 10 years ago) with a great solution. It can be found here: https://wordpress.stackexchange.com/questions/4696/pagination-not-working-with-custom-loop.

The answer that helped me was provided by @ChowKaiDeng (combo of comment from @Jan Fabry and original code by @nurain)

I thought I would post the answer here to show that the solution still works in 2020 with a current version of WordPress and the WP-PageNavi plugin. (The problem appears to be with the PageNavi and the $wp_query variable.)

Here is my code updated with the working solution:

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