Show the Category Names in the Search Results

You can include the category names in the search results by using the wpsl_store_meta filter to collect the category names, and the wpsl_listing_template and wpsl_info_window_template filters to show them in the templates.

Collect the Used Categories

The code example below shows how to collect the category data for each location with wp_get_post_terms and assign the returned category names to the ‘terms’ key.

If a location is assigned to multiple categories, then the category names are separated by a comma (line 18).

add_filter( 'wpsl_store_meta', 'custom_store_meta', 10, 2 );

function custom_store_meta( $store_meta, $store_id ) {

	$terms = get_the_terms( $store_id, 'wpsl_store_category' );

	$store_meta['terms'] = '';

	if ( $terms ) {
		if ( ! is_wp_error( $terms ) ) {
			if ( count( $terms ) > 1 ) {
				$location_terms = array();

				foreach ( $terms as $term ) {
					$location_terms[] = $term->name;
				}

				$store_meta['terms'] = implode( ', ', $location_terms );
			} else {
				$store_meta['terms'] = $terms[0]->name;
			}
		}
	}

	return $store_meta;
}

Show the Category Names in the Templates

After collecting the category names you still need to show them in the used templates.

Search Results Template

The code below shows the search results template with the category names placed directly below the address details ( line 24 – 26 ).

Marker Info Window Template

If you also want to show the used categories in the marker info window, then you can use the code example below. The category data is included between line 16 and 18.

All code examples need to go in the functions.php inside your active theme folder.

Make sure to flush the cache from any possible caching plugins, your browser cache, and the WPSL transient cache on the WPSL settings page before reloading the store locator page.