Mapress pro : use taxonomies to generate maps
Mappress pro, a plugin for wordpress, is worth its price : it can automatically create maps from custom fields adresses. I needed the possibility to create maps from a specific taxonomy, and this requires some hacking. here's the way to go for serious coders who want, like me, to spend one intense hour . hope mappress pro incorporates that for future buyers !!
FIRST STEP : create a new configuration option for mappress to specify the custom taxonomy
- in mappress.php
add_setting_field('customTaxonomyMap', __("Custom Taxonomy", 'mappress'), array(&this, 'setTaxonomy'), 'mappress', 'mappress_pro_settings'));
function set_custom_taxonomy_map() {$options = Mappress_Options::get();$pro_link = "<a href='http://wphostreviews.com/mappress/mappress-pro' title='MapPress Pro'>MapPress Pro</a>";printf(__("This setting requires %s. Automatically create maps from custom taxonomy.", 'mappress'), $pro_link);}in mappress_pro.php
-
function set_custom_taxonomy_map() { $options = Mappress_Options::get(); echo __(" Update map when terms are added to a post in the following taxonomy ", "mappress"); echo "<input type='text' size='30' name='mappress_options[customTaxonomyMap]' value='" . $options->customTaxonomyMap. "'/>";}
- and in mappress_api, don't forget to declare your new option as class variable of Mappress_Options
$customTaxonomyMap=""
SECOND STEP : implement action hooks to create the map when the post is saved
- in mappress_pro.php, function Mappress_Pro()
if ($options->customTaxonomyMap) { add_action('deleted_term_relationships', array(&$this, 'term_delete'), 10, 4); add_action('added_term_relationship', array(&$this, 'term_added'), 10, 4); }
- and
function getTaxonomyMapKey($taxonomy) { return "tax" . $taxonomy; } function term_added($postid, $termId) // poleouest { $options = Mappress_Options::get(); $taxonomy=$options->customTaxonomyMap; $mapMetaKey=$this->getTaxonomyMapKey($taxonomy); $pois=array(); $this->term_delete($postid, $termId); $terms=get_the_terms( $postid, $taxonomy ); foreach( $terms as $term ) { $city=$term->name; add_post_meta($postid,"hello",$city); if ($city!="") {$atts = array("address" => $city); $atts = $this->scrub_atts($atts); $poi = new Mappress_Poi($atts); $result = $poi->geocode(true); $pois[] = $poi; $map = new Mappress_Map(); // Update with new POIs $map->update(array('pois' => $pois, 'title' => $city, 'metaKey' =>$mapMetaKey, 'center' => array('lat' => 0, 'lng' => 0))); $map->save($postid); } } } function term_delete($postid, $termId) // poleouest { $options = Mappress_Options::get(); $taxonomy=$options->customTaxonomyMap; $mapMetaKey=$this->getTaxonomyMapKey($taxonomy); $map = Mappress_Map::get_post_map($postid, null, $mapMetaKey); if ($map) $map->delete(); }
This code seems to be incomplete. Can you post get_the_terms() and also provide some insite into the format if the taxonomy of the customTaxonomyMap ?