WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;

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'); ?>/">
    <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="" />

share|improve this question

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

Your Answer


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.