Display number of results in search page on WordPress

Marc0

Well-known member
Registered
Joined
Jun 6, 2012
Messages
890
Points
28
When a visitor made a search in wordpress it does not return the number of results found. Of course in many cases it is very useful one know how much the results are followed the way to achieve it.

Simply locate the file search.php and in this we are looking for the following line of code:

<h2> Search Results </ h2>

Replace it with the following code


Code:
<h2> Search Results for <? php  
  / * Search Count * /  
  $ 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 ('-');  
  echo $ count.  ''; _e ('Articles');  

  wp_reset_query ();?> </ h2>
Hope it's helpful to you!
 

jdunhin

Active member
Registered
Joined
Feb 27, 2013
Messages
72
Points
0
Nice code, thank you for sharing! I know I'm going to use it :)
 

Marc0

Well-known member
Registered
Joined
Jun 6, 2012
Messages
890
Points
28
Thanks.
You can use it to count number of search results somewhere in your search page. it's useful for viewers.
 
Older Threads
Replies
0
Views
2,002
Replies
1
Views
2,278
Replies
1
Views
3,946
Replies
11
Views
4,174
Replies
23
Views
9,345
Newer Threads
Latest Threads
Recommended Threads
Replies
4
Views
5,936
Replies
34
Views
11,728
Replies
7
Views
3,479
Replies
2
Views
2,203
Replies
14
Views
6,076

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top