Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

i added this

$query_vars['s'] = "Please Enter Keyword to search ";

It's working.this may question may useful for some other.:) anyhow thanks friends.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.