I have a search.php page in my template which works fine when used with the native search widget, but I am making a search plugin which has a custom wp_query in it and I want those results to appear on search.php INSTEAD of regular search widget results.
My plugin so far works well, I "just" want it outputted in search.php.
I tried adding pre_get_posts
filter and also posts_search
action but the filter hook shows "the connection was reset" in the browser and the action hook does the same PLUS it gives a WP Database error on the page where the plugin is loaded.
Relevant part of the function that makes the query:
$blog_url = get_bloginfo('url');
$form = <<<EOH
<div id="sbc">
<form method="get" action="{$blog_url}" id="ss-search">
<input type="text" value="{$search_text}" name="supers" onblur="if (this.value == '') { this.value = '{$search_text}';}" />
{$list}
<input type="submit" id="sbc-submit" value="Search" />
</form>
</div>
EOH;
if (isset($_GET['supers'])) {
global $q;
// global $q;
$args = array(
// 'category__not_in' => 1,
's' => $_GET['supers'],
'paged' => get_query_var('paged')
);
$q = new WP_Query($args);
if ( $q->have_posts() ) {
echo '<ul>';
while ( $q->have_posts() ) {
$q->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
// echo '<br>Posts found :'.$q->found_posts.'<br><br>';
echo get_pagination_links2();
} else {
echo 'no posts found';
}
/* Restore original Post Data */
wp_reset_postdata();
}
return $form;
} // end function