I don’t think this is doing what you think it’s doing, but there’s a trivial solution
Use The s
parameter with a pre_get_posts
filter
Using s
as the name of your input will allow you to do a direct search via the main query, speeding up the page load.
Additionally, you can then modify the search using the pre_get_posts
filter to add the other parameters you want, e.g.
add_filter( 'pre_get_posts', function( \WP_Query $q ) {
if ( !$q->is_main_query() || !$q->is_search() ) {
return;
}
$q->set( 'posts_per_page', 2 );
// etc...
} );
But I Don’t Want To Use search.php
, I A Different Template For This Particular Thing
That would be another question you should ask separately, but luckily, somebody beat you to it: