#I have modified the main loop query via
query_posts()
. Why isn't pagination working, and how do I fix it?I have modified the main loop query via
query_posts()
. Why isn't pagination working, and how do I fix it?
Great answer Chip created needs to be modified today.
For some time we have $wp_the_query
variable that should be equal to the $wp_query
global just after the main query executes.
This is why this the part from the Chip's answer:
###Hack the main query object
Hack the main query object
is not needed anymore. We can forget this part with creating the temporary variable.
// Pagination fix
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $custom_query;
So now we can call:
$wp_query = $wp_the_query;
or even better we can call:
wp_reset_query();
Everything other Chip outlined stays.
After that query-reset-part you can call the pagination functions that are f($wp_query)
, — they depend on $wp_query
global.
In order to further improve the pagination mechanics and to give more freedom to the query_posts
function I created this possible improvement: