Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting the total count of search results in wordpress

How to get the total count of results, in the search results page in wordpress ... i think my question is clear .i need the total number of search results that displayed in the search results page .And also need to find the count of results from page and post separately
what i have tried is

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

by using this i got the total number of search results . but i also need the count of pages and posts in the search results

like image 813
Adarsh Avatar asked May 15 '18 11:05

Adarsh


Video Answer


2 Answers

Try this code,

$allsearch = new WP_Query("s=$s&showposts=0"); 
echo $allsearch ->found_posts.' results found.';

Hope this will helps you.

For more please visit,

Result Count in WordPress

Display Search Result Count

like image 95
Sunil Dora Avatar answered Nov 15 '22 04:11

Sunil Dora


Once you are already in a search query, you can as well use the global $wp_query.

See example below:

<?php
   global $wp_query;
   $not_singular = $wp_query->found_posts > 1 ? 'results' : 'result'; // if found posts is greater than one echo results(plural) else echo result (singular)
   echo $wp_query->found_posts . " $not_singular found";
?>
like image 26
nixx Avatar answered Nov 15 '22 04:11

nixx