Subscribe On YouTube

Join other subscribers and enjoy other Divi video tutorials!

How To Show The Number Of Search Results In The Divi Search Results Template

Nelson Miller Profile Orange
In this tutorial I will show you how to show the number of search results in the Divi search results Theme Builder template.

▶️ Please watch the video above to get all the exciting details! 👆

Search Results Template Setup

This tutorial will not cover how to set up the search results template. If you need help with that, I suggest checking our other tutorial: How To Customize And Style The Divi Search Module And Create A Search Results Page.

To get up to where our tutorial starts, you would need to do these steps:

  1. Create A Theme Builder Template Assigned To “Search Results”
  2. Add a Blog module and set it to “Show Posts For Current Page”

Be sure to watch the video for this tutorial, it will really help!

1. Add The Shortcode To A Text Module

The first step will be to add a new Text module above the Blog module. This will be used for the main heading that reads out with the number of results. To make this work with a dynamic number, we need to add a shortcode to the Text module. The shortcode will output the code which will say the number of results, like “23 results for “divi”.” The shortcode will be powered by a snippet, which we will talk about in step #2.

Shortcode

[pa_search_results_count] 
add shortcode to show the number of search results in Divi

2. Add The PHP Code

The second step now is to add the PHP code that is working behind the scenes and connected to the shortcode. This step involves pasting the PHP code snippet below into your website. There are a number of locations to add this, and it will totally depend on your website and experience.

Where To Paste The PHP Code

1. Divi Assistant
If you are using our Divi Assistant plugin, simply paste the code in the PHP tab in the custom code window in the Divi Visual Builder.

2. Child Theme
If you are using a child theme, paste this code into the functions.php file. If you don't have a child theme, you can generate a child theme directly on your site or download our free child theme.

3. Code Snippet Plugins
Otherwise, install a dedicated code snippet plugin, create a new snippet, and paste this code into the PHP code editor.

If you need help understanding where to paste the code, please check out our complete guide about where to add custom PHP code snippets in Divi.

Snippet

function pa_search_results_count_shortcode($atts, $content=null){
    extract( $atts = shortcode_atts(
        array(
            ''             => '',
            ), $atts, 'pa_search_results_count' ) );
    ob_start();
?>

    <?php
        global $wp_query;
        $items_total = $wp_query->found_posts;
        echo $items_total.' Results for "'.get_search_query().'"';
    ?>

<?php
    return ob_get_clean();
}
add_shortcode('pa_search_results_count','pa_search_results_count_shortcode' );

Edit The Text

If you want to edit the text, you can easily do so by editing the text within the code. Look for the “Results for” text and this is where you can carefully edit it. For example, you may change it to Search Results For Your Query: and this would read out as “[x] Search Results For Your Query: [search term]”

Do It With Our Divi Search Helper!

Make life easier and use the Divi Search Helper instead! This innovative plugin upgrades the existing Divi Search module with all the missing features provided by our addon with new design settings, advanced search criteria options, and improved search result pages.

Divi Search Helper Plugin By Pee Aye Creative

Subscribe For More Things Like This!

At the start of each month, we send out a recap newsletter from the month before with family news, Divi news, our latest tutorials, and product news. Occasionally, if the news is too exciting to wait, we will send out another email separate from the monthly newsletter. That’s what you get when you subscribe, and of course you can unsubscribe if you are no longer interested!

Blog Post Optin
Divi Logo (2)

Shop Our Divi Products

Plugins • Courses • Templates

Visit The Shop

Featured Products

Asset 4

New! Trail Guides

Follow a series of blog posts carefully arranged around a specific topic or goal! Keep track of your progress by marking posts completed, just like a free course!

View Trial Guides

Divi Trail Committee Membership badge with map design

Join The Trail Committee!

Show support for our ongoing work creating community resources at Pee-Aye Creative and enjoy exclusive member perks in return.

Learn More

Divi Tutorials On YouTube

Our videos have views! Join subscribers and enjoy over video tutorials!

Visit Our Channel

Leave A Response!

By commenting you agree to our Blog & YouTube Comments Policy

4 Comments

Comments By Others

  1. Manos

    Hello Nelson! Great tutorial and really glad to have you in the Divi community!

    I would like to ask you, why everytime I use different language in the ” Results for ” it displays the shortcode instead of the echo text?

    Thanks in advance!

    Reply
    • Hemant Gaba <span class="comment-author-role-label"><a href="https://www.peeayecreative.com/product/divi-adventure-club/" class="comment-author-role-link" rel="external nofollow" target="_blank">Divi Adventure Club Member</a></span>

      Hi Manos!

      Can you share the PHP code along with the website URL you’re using to investigate further?

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Recent Posts

0

Your Cart