code - Search Count Wordpress Theme

admin2025-06-02  2

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">
<?php 
printf( esc_html__( 'Search Results for: %s', 'musik' ), '<span class="font-bold">' . get_search_query() . '</span>' );

 ?>
</h1>

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">
<?php 
printf( esc_html__( 'Search Results for: %s', 'musik' ), '<span class="font-bold">' . get_search_query() . '</span>' );

 ?>
</h1>
Share Improve this question edited Jan 18, 2019 at 7:49 Gufran Hasan 6918 silver badges20 bronze badges asked Jan 18, 2019 at 5:52 Neo MorakileNeo Morakile 1 2
  • And what would you like to see instead? – Krzysiek Dróżdż Commented Jan 18, 2019 at 6:13
  • i would like to see the number of search results found – Neo Morakile Commented Jan 18, 2019 at 6:40
Add a comment  | 

2 Answers 2

Reset to default 1

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.

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

?>

</h2>

Reference link

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748855235a314281.html

最新回复(0)