WordPress Pagination with Custom WordPress Queries

I don’t remember the last time I made a WordPress theme that didn’t do all sorts of unique stuff. I’ve never been interested in making standard blog designs and always want to create something a bit different. This throws up some issues then – most often with pagination – and it’s only recently that I found a solution.

x_posts_link

I had always assumed that the next_posts_link and previous_posts_link functions were for use in combination with ‘the loop’, but it seems that’s not the case. Upon closer inspection they just dissect the url and increment or decrement the number of pages. By default they use the properties inside the loop, but you can override them.

In fact it turns out the only value you need to pass is the maximum number of pages in the query and this can be accessed through the query itself.