Displaying other pins on a map
Support › MB Geolocation › Displaying other pins on a map
- This topic has 2 replies, 2 voices, and was last updated 6 days, 11 hours ago by
Peter.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
June 24, 2025 at 8:08 PM #48500
Aidan van Vuuren
ParticipantHi
I am trying to display other pins in a map output, but this doesn't seem to be working, how can I do it?
function custom_map_shortcode( $atts ) { $atts = shortcode_atts( array( 'id' => 'maps_location', 'object_id' => get_queried_object_id(), ), $atts ); if ( ! $atts['id'] || ! $atts['object_id'] ) { return 'Field ID and post context are required.'; } $main_location = rwmb_meta( $atts['id'], '', $atts['object_id'] ); if ( empty( $main_location ) ) { return 'No primary map data found.'; } $extra_pins = array( array( 'latitude' => 53.46565740326415, 'longitude' => -2.2326974824510635, 'title' => 'University of Manchester', 'content' => '<strong>Manchester</strong><br>Premier university.', 'icon' => '/wp-content/uploads/2025/03/Map-Pin-Small-2.svg', ), array( 'latitude' => -33.920, 'longitude' => 18.423, 'title' => 'Cape Peninsula University of Technology', 'content' => 'CPUT Campus', 'icon' => '', ), ); $map_args = array( 'width' => '100%', 'height' => '480px', 'zoom' => 13, 'marker' => true, 'marker_icon' => '/wp-content/uploads/2025/03/Map-Pin-Small-2.svg', 'js_options' => array( 'mapTypeId' => 'HYBRID', 'zoomControl' => true, 'zoomControlPosition' => 'topright', 'markers' => array(), // Initialise empty markers array ), ); // Add extra pins foreach ( $extra_pins as $pin ) { $map_args['js_options']['markers'][] = array( 'latitude' => $pin['latitude'], 'longitude' => $pin['longitude'], 'title' => $pin['title'], 'infoWindow' => $pin['content'], 'markerIcon' => $pin['icon'], ); } ob_start(); rwmb_the_value( $atts['id'], $map_args, $atts['object_id'] ); return ob_get_clean(); } add_shortcode( 'custom_map', 'custom_map_shortcode' );
Demo site: https://aidanv14.sg-host.com/property/osborne-road-accommodation-3/
June 24, 2025 at 8:11 PM #48501Aidan van Vuuren
ParticipantCode in pastebin: https://pastebin.com/AJRfWqT9
June 24, 2025 at 9:29 PM #48502Peter
ModeratorHello Aidan,
Thanks for reaching out.
If you want to display more addresses (pins) on a map, please follow this tutorial
https://docs.metabox.io/tutorials/display-listings-on-map/Note: Supporting the customization code is beyond our scope of support. If you are not able to complete the task, we offer a customization service with an extra fee. Please contact us here for more details https://metabox.io/contact/
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.