Adrian
Adrian

Reputation: 2012

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.

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

Thank you.

Upvotes: 1

Views: 2547

Answers (1)

Surinder kumar
Surinder kumar

Reputation: 380

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');

Upvotes: 1

Related Questions