I have a code that displays results for search but, I need it to include the count not just keyword searched

<h1 class="font-thin h2 m-b">
printf( esc_html__( 'Search Results for: %s', 'musik' ), '<span class="font-bold">' . get_search_query() . '</span>' );

  • And what would you like to see instead? – Krzysiek Dróżdż Jan 18 '19 at 6:13
  • i would like to see the number of search results found – Neo Morakile Jan 18 '19 at 6:40

If you are in the search results template then you can find out the count by using the below code.

global $wp_query;
$count =  $wp_query->found_posts

variable $count contains the count of post against the search.

| improve this answer | |

Please open and modify this line in search.php.

<h1 class="font-thin h2 m-b">
Search Result for <?php 
/* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); 
$key = wp_specialchars($s, 1); 
$count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); 
echo $key; _e('</span>'); _e(' &mdash; '); 
echo $count . ' '; _e('articles'); 



Reference link

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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