Created
June 26, 2012 22:59
-
-
Save webaware/2999934 to your computer and use it in GitHub Desktop.
Using WordPress custom fields to drive WP Flexible Maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
In reply to this request: | |
http://wordpress.org/support/topic/plugin-wp-flexible-map-updating-the-map-from-custom-field-data | |
add a simple [map] shortcode to WordPress that allows maps to be | |
created from custom fields: | |
"map zoom" = the zoom level (will default to 12 if not set) | |
"map coordinates" = coordinates for the map | |
"map address" = address for the map | |
You must specify either coordinates or address (not both). | |
*/ | |
if (!is_admin()) { | |
add_shortcode('map', 'custom_shortcodeMap'); | |
} | |
/** | |
* handle shortcode for map display | |
* | |
* @param array shortcode attributes as supplied by the WP shortcode API | |
* @return string output to substitute for the shortcode | |
*/ | |
function custom_shortcodeMap($attrs) { | |
global $post; | |
$html = ''; | |
if (isset($post) && function_exists('flexmap_show_map')) { | |
$zoom = get_post_meta($post->ID, 'map zoom', true); | |
if (!$zoom) { | |
$zoom = 12; | |
} | |
$coords = get_post_meta($post->ID, 'map coordinates', true); | |
if ($coords) { | |
$map = array( | |
'center' => $coords, | |
'width' => 500, | |
'height' => 400, | |
'zoom' => $zoom, | |
); | |
$html = apply_filters('flexmap_getmap', $map); | |
} | |
else { | |
$address = get_post_meta($post->ID, 'map address', true); | |
if ($address) { | |
$map = array( | |
'address' => $address, | |
'width' => 500, | |
'height' => 400, | |
'zoom' => $zoom, | |
); | |
$html = apply_filters('flexmap_getmap', $map); | |
} | |
} | |
} | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment