Count your wordpress search results

The default WordPress search results page is noting but to show you the total results as per your search keywords. You can spice this page up a bit by showing the total search count like
4 Results found or something like this….

Just you need to add some codes and it will look like the image below.

The main code which do this action is:

<?php $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; ?>

Now what you will have to do is as follows.

Step 1: Open search.php page inside your theme folder. Remove the existing search query and put the following code.

Step 2: Save the file and check the updates doing some search.

If you are new to WordPress theme modification then make sure you will not basic WordPress template function like header, sidebar and footer as get_header(); get_sidebar(); and get_footer();

You can modify the code for style purpose or adding more ingredients on search.

You may also like

4 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.