admin管理员组文章数量:1122846
I have private pages in my website, so i have used this filter to hide some of the pages,
function mySearchFilter($query) {
if ($query->is_search) {
$excludeId = get_option('page_for_posts');
$query->set('post__not_in', array('267','287'));
}
return $query;
}
add_filter('pre_get_posts','mySearchFilter');
it's working perfectly but if i click empty search means it shows some default pages .. how to restrict the empty search?
I tried this one and it's not working for me.
add_filter( 'request', 'my_request_filter' );
function my_request_filter( $query_vars ) {
if( isset( $_GET['s'] ) && empty( $_GET['s'] ) ) {
$query_vars['s'] = " ";
}
return $query_vars;
}
this is my search form
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
<div>
<input type="text" class="search_text" name="s" id="s" value="<?php echo trim( get_search_query() ); ?>" />
<!--<input type="text" class="search_text" value="<?php the_search_query(); ?>" name="s" id="s" />-->
<input type="submit" id="searchsubmit" class="search_btn" value="" />
</div>
</form>
I have private pages in my website, so i have used this filter to hide some of the pages,
function mySearchFilter($query) {
if ($query->is_search) {
$excludeId = get_option('page_for_posts');
$query->set('post__not_in', array('267','287'));
}
return $query;
}
add_filter('pre_get_posts','mySearchFilter');
it's working perfectly but if i click empty search means it shows some default pages .. how to restrict the empty search?
I tried this one and it's not working for me.
add_filter( 'request', 'my_request_filter' );
function my_request_filter( $query_vars ) {
if( isset( $_GET['s'] ) && empty( $_GET['s'] ) ) {
$query_vars['s'] = " ";
}
return $query_vars;
}
this is my search form
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
<div>
<input type="text" class="search_text" name="s" id="s" value="<?php echo trim( get_search_query() ); ?>" />
<!--<input type="text" class="search_text" value="<?php the_search_query(); ?>" name="s" id="s" />-->
<input type="submit" id="searchsubmit" class="search_btn" value="" />
</div>
</form>
Share
Improve this question
asked Jan 31, 2012 at 7:17
Ramkumar MRamkumar M
8741 gold badge13 silver badges33 bronze badges
1 Answer
Reset to default 2i added this
$query_vars['s'] = "Please Enter Keyword to search ";
It's working.this question may useful for some other.:) anyhow thanks friends.
本文标签: customizationHow to Clear Empty Search values
版权声明:本文标题:customization - How to Clear Empty Search values? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736291270a1928688.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论