I often use Store Locator Plus plugin to have a store locator on a site. This time I wanted to show a total number of locations present in the locator in my theme design.
I’ve made a shortcode to display locations count in a widget. We put this into child theme functions.php
// shortcode [totalLocations]
function locations_number( $atts ) {
global $wpdb;
$table_name = $wpdb->prefix . 'store_locator';
$atts = shortcode_atts( array(), $atts, 'totalLocations' );
$totalLocations = $wpdb->get_var("SELECT count(sl_id) FROM " . $table_name );
return '<strong class="total-locations-number">' . $totalLocations . '</strong>';
}
add_shortcode( 'totalLocations', 'locations_number' );
Use it as a regular shortcode anywhere: [totalLocations]
It works with latest WP and SLP. I thought, maybe to add some cache option inside, but no success yet. Any ideas on how to improve it?