Reputation: 23
Yea so on my wordpress theme I've put together...
When you click the search button (with the search field empty) it takes you to the blog page. I have assigned the index.php as the blog page and made another page and assigned that as the home page.
Can anyone help? Its not a major problem but it is a little glitch I would like to get rid of.
Thanks.
Terry
Upvotes: 1
Views: 2873
Reputation: 1472
I also faced the same problem, it is default given by wordpress.
but luckily I found something which helped me.
Add below in "Functions.php"
function SearchFilter($query) {
// If 's' request variable is set but empty
if (isset($_GET['s']) && empty($_GET['s']) && $query->is_main_query()){
$query->is_search = true;
$query->is_home = false;
}
return $query;}
add_filter('pre_get_posts','SearchFilter');
and then replace below line(line no 15) in search.php
<?php if ( have_posts() && strlen( trim(get_search_query()) ) != 0 ) : ?>
Might be it will help you too
For details read this : Customize empty search wordpress
Upvotes: 6