Skip to main content
All CollectionsData Manipulation
How to Manipulate Data with the Available Filters
How to Manipulate Data with the Available Filters
James avatar
Written by James
Updated over 10 months ago

The plugin has filters that developers can use to manipulate the output of the maps.

igm_add_meta

Runs as soon as the plugin fetches the meta information for a given map.

Usage example:

add_filter( 'igm_add_meta', 'igm_custom_meta', 1 ); function igm_custom_meta( $meta ){ //do whatever you want with $meta return $meta; }

igm_prepare_meta

Similar to the previous filter, but runs a bit after.

add_filter( 'igm_prepare_meta', 'igm_custom_meta', 1 ); function igm_custom_meta( $meta ){ //do whatever you want with $meta return $meta; }

More information and examples soon.

igm_map_before

igm_map_after

igm_mapbox_classes

Custom Post Type Example

<?php
/**
* Interactive Geo Maps Callback
*
* @wordpress-plugin
* Plugin Name: Interactive Geo Maps CPT Addon
* Plugin URI: https://interactivegeomaps.com
* Description: Connects CPT with map
* Version: 1.0.0
* Author: Carlos Moreira
* Author URI: https://cmoreira.net/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/

add_filter( 'igm_add_meta', 'igm_cpt_addon', 1 );

/**
* Filter map output
* @param array $meta - meta data from the map
* @return array modified meta
*/
function igm_cpt_addon( $meta ){

// if you want to target a specific map, use this code with your map ID
/*
if ( intval( $meta['id'] ) !== 999 ) {
return $meta;
} */

// you can modify/populate the different types of data. In this example we'll modify 'regions'
// but you could modify 'roundMarkers', 'iconMarkers', 'vectorIcons' and 'labels'.

$post_type = 'tshowcase'; // modify here to set your own custom post type

// we will query the custom post types and loop through them
$args = array(
'posts_per_page' => -1,
'post_status' => 'publish',
'post_type' => $post_type,
);

$posts = get_posts( $args );

$regions = [];

// loop posts.
foreach ( $posts as $post ) {

// in this example we'll get the region code from a custom meta field
// if you're using ACF you can use the function get_field instead

$entry = array(
'id' => get_post_meta( $post->ID, '_tslocation', true ), // this should be the region name or code according to selected map
'title' => $post->post_title,
'tooltipContent' => $post->post_title,
'content' => $post->post_content,
'useDefaults' => '1', // set this to 1, to allow the regions to inherit colors from default settings. If you want to control the colours populate the 'fill' and 'hover' parameters
'customField' => get_post_meta( $post->ID, '_mycustommeta', true ),
//action => 'open_url',
//latitude => 0,
//longitude => 0,
);

// you can populate the entry with whatever custom fields you need. You can then use {customField01} in the tooltip template, to display information from those fields

array_push( $regions, $entry );

}

$meta['regions'] = $regions;

return $meta;
}

In the example below we are populating the map using data from a custom post type.

view rawigm-cpt-addon.php hosted with ❀ by GitHub

Other Examples

Here are a few examples of custom addons developed using the filters above. Most of these will also add extra fields/options to the maps.

Did this answer your question?