Show a map on category / tag / custom taxonomy archives that automatically filters to the current term.
Steps
- Create a map whose main post type matches the archive.
- Embed it in the taxonomy template:
echo do_shortcode( '[cspm_main_map id="65"]' );
- Add this to your child theme
functions.php:
/**
* Filter Progress Map by the current taxonomy term on archives.
*/
function cspm_update_taxonomy_map_settings( $map_settings, $map_id ) {
if ( ! class_exists( 'CspmMainMap' ) ) {
return $map_settings;
}
$CspmMainMap = CspmMainMap::this();
$fields_prefix = $CspmMainMap->metafield_prefix;
if ( is_tax() || is_category() || is_tag() || is_archive() ) {
$queried_object = get_queried_object();
if ( empty( $queried_object->taxonomy ) || empty( $queried_object->term_id ) ) {
return $map_settings;
}
$taxonomy = $queried_object->taxonomy;
$term_id = (int) $queried_object->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 );
Tips
- Restrict the filter to one map:
if ( (string) $map_id !== '65' ) return $map_settings; - Ensure posts on that archive actually have coordinates.
- For more complex overrides (meta, include/exclude), see Override map query.
