Monday, March 25, 2013

Show "Post" count by searching in Wordpress



Sometimes in Wordpress, we need to perform custom search in our blog or site. It is not difficult to perform custom search. When I wanted to show the number of post found after search, I got problem. After google about it, I found the following easy solution.


  echo wp_specialchars($s); // printing the keyword
  $allsearch = &new WP_Query("s=$s&showposts=-1");
  $count = $allsearch->post_count;
  echo ' (' . $count . ') '; // printing the founded post count
  wp_reset_query();

I wish this will help you.

No comments: