Whenever it comes to writing custom queries in WordPress, pagination always seems to give developers problems (myself included!).
I think this can be chalked up to the next / previous pagination links (so does next mean older, or newer?), paginating single posts as well as archive posts, and then occasionally having to write custom queries that include pagination.
One of the areas that I see most confusing – again for myself as well – is properly calculating page offsets especially when working with the WP_Query
offset parameter.
The thing is, I think it can be much more simplified (or, perhaps, demystified?) when visualizing the data that you’re working with, and knowing how to use some of the existing API links.
So here’s what you need to know in order to get pagination working when working with the WP_Query
offset, page, and number parameters.