Get search.php results in header.php?

I want one image in header.php to change for different pages.

The function in header.php looks like that:

Read More
if(is_archive()):
  //change image to "Archives"
endif;
if(is_404()):
 //change image to "404"
endif;

Now, is it possible to check if page is the search page AND what’s the search string AND how many posts were found?

So what I want to do is basically:

if(is_search()):
 //change image to "Search" AND echo %s
endif;
if(is_search_empty()): //yes I made this up
 //change image to "Nothing found" AND echo $
endif;

Is it even possible outside the search.php page loop?

Related posts

Leave a Reply

1 comment

  1. Now, is it possible to check if page is the search page

    is_search()
    

    AND what’s the search string

    is_search() AND print get_query_var( 's' )
    

    AND how many posts were found?

    is_search() AND print $GLOBALS['wp_query']->number_posts()
    

    … or if you got a custom query…

    $my_query = new WP_Query( array( /* whatever args */ ) );
    is_search() AND print $my_query->number_posts()