Divi offers two types of search results pages: the default search results page and a customizable search results page template created with the Theme Builder.
Displaying the Search Results Count on the Default Search Results Page:
In this guide, we'll walk you through the process of displaying the search results count on the theme builder's search results page template in two straightforward steps.
Step 1: Create a search results page template in Theme Builder:
Open the Divi theme's backend and navigate to the Theme Builder.
Create a new template by selecting "Search Results Page" as the assignment.
Edit the template body, and within it, add a Blog Module.
In the Blog Module settings, under Content, enable the "Current Page" option.
For a more detailed guide on creating a custom search results page in Divi, you can follow our step-by-step tutorial.
Step 2: Create a shortcode using PHP to display the number of search results:
Note: This requires a child theme to be installed and active. The child theme can be created using this tutorial.
To display the search results count on the default search results page, you can incorporate custom PHP code, avoiding the need to modify any Core theme files.
You have two options:
Add the provided PHP code to your Child theme's functions.php file.
Utilize the Code Snippets plugin for a hassle-free way to integrate the snippet and display the search results count.
For a comprehensive guide on adding PHP codes to Divi, you can follow this resource.
function divi_search_results_count_shortcode($atts) {
$query = new WP_Query( array( 's' => get_search_query(), 'posts_per_page' => -1 ) );
$count = $query->found_posts;
return '<p>Number of Results: ' . $count . '</p>';
}
add_shortcode('divi_search_results_count', 'divi_search_results_count_shortcode');
The provided code creates a shortcode named divi_search_results_count.
You can add this shortcode to the Text Module or Code Module within the Search Results Page template where you want to display the number of results.
Ensure you enclose the shortcode in square brackets, like this: [divi_search_results_count].