How to get the total count of search results in wordpress?


Here are php code by using you can show your visitors search result count.

 

Try following code.

 

Method-1

Go to theme and open search.php and paste following codes.

<?php echo count($posts); ?>

 

Method-2

Try following WPbeginner codes

<h2 class="pagetitle">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>

 

Method-3

Or directly use following PHP Code in search.php

<?php
global $wp_query;
echo $wp_query->found_posts.’ results found.’;
?>

 

Done….



Find More related How to get the total count of search results in wordpress?


Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *