I have a site that uses a custom query to search for posts by country.
The search results come back fine, but the pagination at the bottom reflects the total number of posts in the site, instead of the total number of posts in the search results.
The plug in that manages this uses global $wp_query to determine the number of posts, instead of the custom query. By default, it works like this:
function wp_page_numbers($start = "", $end = "")
{
global $wp_query;
global $max_page;
global $paged;
if ( !$max_page ) { $max_page = $wp_query->max_num_pages; }
if ( !$paged ) { $paged = 1; }
$settings = get_option('wp_page_numbers_array');
$page_of_page = $settings["page_of_page"];
$page_of_page_text = $settings["page_of_page_text"];
$page_of_of = $settings["page_of_of"];
$next_prev_text = $settings["next_prev_text"];
$show_start_end_numbers = $settings["show_start_end_numbers"];
$show_page_numbers = $settings["show_page_numbers"];
$limit_pages = $settings["limit_pages"];
$nextpage = $settings["nextpage"];
$prevpage = $settings["prevpage"];
$startspace = $settings["startspace"];
$endspace = $settings["endspace"];
if( $nextpage == "" ) { $nextpage = ">"; }
if( $prevpage == "" ) { $prevpage = "<"; }
if( $startspace == "" ) { $startspace = "..."; }
if( $endspace == "" ) { $endspace = "..."; }
if($limit_pages == "") { $limit_pages = "10"; }
elseif ( $limit_pages == "0" ) { $limit_pages = $max_page; }
I tried modifying it to this:
if ($gallery_query){ $page_query=$gallery_query; }else {$page_query=$wp_query;}
global $max_page;
global $paged;
if ( !$max_page ) { $max_page = $page_query->max_num_pages; }
if ( !$paged ) { $paged = 1; }
But that returns no pages.
Ideally, I should replace the $wp_query value with the $gallery_query value, but I don't know how. The obvious $wp_query = $gallery_query
doesn't work.
Any suggestions?
Thanks!
ty
posts_clauses
filter. There're some examples that will solve your needs (modifying the original query).