Replace/Mute/Stop Search Query
I'm trying to replace the search functionality in WP.
I've already created the search.php
template with all the results I want to display.
I don't want any results from the WP database.
I just want to show my results in search.php
using the native searchform.php
and the native ?s=keyword
URL structure.
Doing that because of SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts ...
search built in query with is very CPU consuming.
So in my themes functions.php I added:
add_action('pre_get_posts', 'no_search_query');
function no_search_query($query) {
if($query-is_search() $query-is_main_query() get_query_var('s', false)) {
unset( $query-query_vars['s'] );
$query-set( 'post__in', '' );
}
}
and added:
$is_search_query = ($_GET["s"]) ? ($_GET["s"]) : 0;
to my search.php to get the search keyword.
This actually did the trick but the query is still being called.
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type IN ...
The call to the database is now a lot of less consuming (there are no arguments) but its still a call to the database which I want to eliminate.
Any idea how to do that?
Best regards.
Topic pre-get-posts search-engines database query Wordpress search
Category Web