In this tutorial you learn how to add Search Term and Search Result Count in your WordPress search page, I was looking for this functionality to add in my new WordPress site, currently the one you’re viewing now yayyyyyy ;) .
Search Term and Search Count is a bit helpful for users who search your site, it help them know how many post they’re currently viewing.
Open your search.php file under your theme directory and add this code.

Solution 1:

PHP
1
2
3
4
5
global $wp_query;
$count = $wp_query->post_count;
$term = $wp_query->query_vars; // this result array of available fields.
echo $term['s'].’ – ‘.$count.’ Results’;

Solution 2:

PHP
1
2
3
4
$allsearch = &new WP_Query(“s=$s&showposts=-1″);
$key = wp_specialchars($s, 1);
$count = $allsearch->post_count; _e(”);
_e(‘<span>”‘);  echo $key; _e(‘”</span>’); _e(‘ &mdash; ‘);  echo $count . ‘ ‘; _e(‘results’); wp_reset_query();
Source in Solution 2: from WP Beginner

Sample demo / to feel more try searching:

SEARCHING FOR PHP – 4 RESULTS
Add CSS code to make your search term and search count alive, that’s it hope it helps ;) .

0 comments:

Post a Comment

 
Top