$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>code - Search Count Wordpress Theme|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

code - Search Count Wordpress Theme

matteradmin7PV0评论

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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far