Where intelligence is put to the test.

WordPress Pagination in Custom Loop

John Crenshaw in wordpress

Oct 16

If you use custom loops in WordPress you may run into pagination issues. Specifically, no matter what page you’re on, only the first page’s worth of posts are displayed. Here’s a really quick solution to that problem using the query_posts() function.

I wrote an article a while back about using a static homepage for your WordPress blog. In that article I mentioned using a custom loop on this blog in the blog and tutorials sections. One problem you may run into when using a custom loop is that pagination doesn’t work like you’d expect it to.In particular, you may notice that only the first page of posts are displayed no matter what page of posts you’re trying to view. I often use WordPress as a general purpose CMS in client projects and so I use a lot of custom loops and run into this issue a lot. Here’s the solution:

Update query_posts with the proper query vars

The solution to this problem is pretty simple. You need to tell WordPress to use the “paged” query variable in your custom loop, otherwise it’s ignored. If you’re using the query_posts function for your custom loop, the easiest way to do this is like so:

1
2
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('paged=' . $paged . '&cat=76'); // show posts in category 76 with pagination enabled

In this example, we first test to see if the “paged” query variable is set using the get_query_var function, which will return false if it’s not set. If it is set, we’ll set $paged equal to the value of that query variable and if not, we’ll set it equal to 1.

Then we initialize our custom loop using the query_posts function by setting “paged” equal to our $paged variable so that WordPress grabs the current page from the URL and displays the appropriate list of posts for that page.

I’m also looping through the posts in category #76 in this example, which is only there for illustrative purposes. That’s all there is to enabling pagination in custom WordPress loops.

Written by John Crenshaw

More from John Crenshaw
Choosing the Right Enterprise SEO Agency: 2026 Vetting Guide

Scaling organic search for a large organization is fundamentally different from small business SEO. You're not just optimizing a few dozen pages; you're managing tens of thousands, or even millions,…

How to Do a Website Audit That Actually Boosts Revenue

So, you need to do a website audit. At its core, this means systematically breaking down your site’s technical health, on-page content, and user experience to find out what’s holding…

7 Powerful YouTube Dashboard Examples to Master Your Channel in 2026

YouTube's native analytics are powerful, but they don't always tell the whole story or connect performance to your broader marketing goals. A well-designed dashboard transforms raw data into a strategic…

Data driven marketing strategies: A Practical Growth Guide

Data-driven marketing strategies live and die by the quality of your customer data. It's the bedrock. Without a solid foundation, you're just guessing. Confused about where to start? Get a…

How to Calculate Marketing ROI and Prove Your Real Impact

Let's cut right to the chase. The simplest way to figure out your marketing return on investment is with this formula: (Revenue - Marketing Investment) / Marketing Investment. This little…

The Ultimate 10-Point PPC Audit Checklist for 2025

Pouring money into PPC campaigns without regular, in-depth audits is like navigating a maze blindfolded. You're moving, but are you getting closer to your goal? Many businesses leak significant portions…

Ready to talk? We’re listening.

If you have questions we have answers. And probably some questions for you, too.

Let’s get after it!

Let's Get Started