GeoDirectory already counts the listings that match a search. You can show that number in the search page title or next to the page numbers without writing any code, or print it anywhere with a short snippet.
Put the count in the search page title
- Go to GeoDirectory > Settings > General > Titles & Meta.
- Scroll to the Search page section.
- In the Title field, combine the %%postcount%% variable with the search variables, for example
%%postcount%% results %%for_search_term%% %%search_near%% - Save changes.
A search for pizza near Dublin that matches 12 listings then gets the title “12 results for pizza near Dublin”. The same variables work in the Meta Title and Meta Description fields of that section.
Show “Showing listings 1-10 of 42” with the pagination
The GD > Loop Paging widget or block on your search template page has a setting called Show Advanced pagination. Set it to Before, After, Inline Before or Inline After to add a line such as “Showing listings 1-10 of 42” next to the page links. Choose Only (hide paging) if you want the line without the page links. As a shortcode it looks like this:
[gd_loop_paging show_advanced="before"]
This line only appears when the results run to more than one page, because the paging widget outputs nothing for a single page of results. The search template page is the one selected at GeoDirectory > Settings > General > Pages > Search Page.
Show the count anywhere with a snippet
If you want the number somewhere else on the search page, this snippet adds a [my_gd_result_count] shortcode. Add it with the Code Snippets plugin or your child theme’s functions.php, then place the shortcode on the search template page.
add_shortcode( 'my_gd_result_count', function() {
global $wp_query;
if ( ! function_exists( 'geodir_is_page' ) || ! geodir_is_page( 'search' ) || empty( $wp_query ) ) {
return '';
}
$count = (int) $wp_query->found_posts;
return sprintf( _n( '%d result', '%d results', $count, 'textdomain' ), $count );
} );