wordpress is_search not working

Im trying to check if Im on the search page, so I can add my own custom query parameters, but it doesnt seem to work. When I look for “this is a test”, I cant find in on the search results page.

I have this code inside functions.php and im using the search.php template to display my search results.

Read More
if( is_search() ){
    echo 'this is a test';
    $query->set( 'posts_per_page', 5 );
        }

Thank you.

Related posts

Leave a Reply

1 comment

  1. May be this will help you to alter your search request.

    function customSearch($query){
        if ( $query->is_search() ) {
             // add external search form (Google, Yahoo, Live...)
             $query->set( 'posts_per_page', 5 );
        }   
    }
    
    add_filter('pre_get_posts','customSearch');