Insert a map inside a taxonomy page and display locations based on the current taxonomy term


In this tutorial, you’ll see how you can insert your map inside a taxonomy page and automatically display locations based on the current taxonomy term.

  1. Create a new map #.
  2. Use the PHP code to insert your map inside your taxonomy page #. (e.g. echo do_shortcode('[cspm_main_map id="65"]'); ).
  3. Copy/Paste the following code in the file “functions.php” of your theme/child theme:
/**
 * Automatically display locations based on the current taxonomy term.
 * Works for "Progress Map v3" and above 
 */
function cspm_update_taxonomy_map_settings($map_settings, $map_id){

	if (!class_exists('CspmMainMap'))
	 return; 
	
	$CspmMainMap = CspmMainMap::this();
	
	$fields_prefix = $CspmMainMap->metafield_prefix;
	
	if(is_tax() || is_category() || is_tag() || is_archive()){
		
		$queried_object = get_queried_object();

		$taxonomy = (isset($queried_object->taxonomy)) ? $queried_object->taxonomy : ''; // The taxonomy slug/name
		$term_id = (isset($queried_object->term_id)) ? $queried_object->term_id : ''; // The term ID
			
		$map_settings[$fields_prefix.'_taxonomie_'.$taxonomy] = serialize(array($term_id));
		
	}
	
	return $map_settings;
	
}
add_filter('cspm_map_settings', 'cspm_update_taxonomy_map_settings', 10, 2);

In the same context