Let’s say I’m doing a search on my site, and get 50 posts as a result. The pagination is set to 10 posts per page, so I have 5 pages of results.
When I’m on the first page of results, if I inspect the global var $posts
, it gives me data for the 10 posts of the current results page only.
How can I access the data of ALL the results, no matter which page I’m on?
The whole loop mechanism is based around having a filtered $posts array. So looking in The Loop documentation on multiple loops it gives a PHP explanation for the standard loop code you use:
So the global $posts is connected to the have_posts function. For that to work properly it can only contain the paginated list of posts. Also note that the $posts array is only there for backwards compatibility so its best not to access it directly anyway.
So it looks like you’ll have to either set up your own pagination or create a separate object with all posts.
I’d suggest the latter.