Hi,
The initial question was good. I had the same problem – have page with custom query
$pageposts = $wpdb->get_results(“select …”, OBJECT);
if ($pageposts):
foreach ($pageposts as $post):
setup_postdata($post); ?>)
…
with many post as a result.
The problem is that navigation functions next_posts_link and previous_posts_link don’t work here. Of course, it works if one writes his own navigation functions, but I prefer to use WP navigation way. So, the solution is to ‘put’ this query in the loop ant to use wordpress functionality.
Just change the search form(searchform.php) and add the following line <input type=”hidden” name=”key” value=”<what you want>” /> – just before <input type=”submit” id=”searchsubmit” value=”Search” />
Let say you have
<input type=”hidden” name=”key” value=”pretty” />
Thus the url by searching something(f.i. word ‘dog’) would be
https://…../?s=dog&key=pretty
Then get the plugin Search Custom Fields and modify it a bit. The functions in the plugin get
the search word (dog) and the value of the key(pretty).
Add one if() to szub_search_custom_join and szub_search_custom_where functions – if the value of the key is ‘pretty’, change the functions szub_search_custom_join and szub_search_custom_where in such way, like normal search is performed – only the word ‘dog’ will be searched without any additional JOIN and WHERE
f.i.
function szub_search_custom_where($where) {
…
…
if ($_GET[‘key’] == ‘pretty’) {
$where = ” (1=1) AND $status “;
}
}
return $where;
But if key has other value – f.i. ‘myname’, then set variable $join in szub_search_custom_join and $where in szub_search_custom_where so, like your custom query will be executed (you can use also search word here – dog in this example).
So, if you use https://…../?s=dog&key=myname – then the output will be your custom query. And this will come from the loop – so navigation is ok and so on.
Hope this help.
Regards.