Hello,
I'm using Toolset to create a single event template for The Events Calendar. However, I'm struggling to get the Venue Location to show.
The Events Calendar plugin stores Venues as a separate post type, and links to the venue post using the field '_EventVenueID'. So I've used this as a basis to get Venue data into the Single Event template - e.g. [wpv-post-field name='_VenueCity' id="[wpv-post-field name='_EventVenueID']
However, I'm struggling to get a map to show with the Venue Location. Using the map block doesn't appear to give any usable options so I'm thinking a shortcode approach is best. I tried something like this for the marker but it doesn't appear to be working - [wpv-map-marker map_id="my-map" marker_id="my-marker" lat="[wpv-post-field name='_VenueLat' id="[wpv-post-field name='_EventVenueID']" lon="[wpv-post-field name='_VenueLng' id="[wpv-post-field name='_EventVenueID']"][/wpv-map-marker] - because I think there are two many levels of nested shortcodes?
Any suggestions on how to get this to work?
Thanks
Hi,
Thank you for contacting us and I'd be happy to assist.
During my tests, I was able to show the venue's map marker on the single event page, using the following steps:
1. I registered a custom shortcode, which first gets the current event's venue ID and then extracts the address items from its custom fields to return a complete formatted address:
add_shortcode('venue_address_custom', 'venue_address_custom_func');
function venue_address_custom_func( ) {
$current_event = do_shortcode("[wpv-post-id]");
$current_event_venue = do_shortcode("[wpv-post-field name='_EventVenueID']");
$venue_address = do_shortcode("[wpv-post-field name='_VenueAddress' id='".$current_event_venue."']");
$venue_city = do_shortcode("[wpv-post-field name='_VenueCity' id='".$current_event_venue."']");
$venue_state = do_shortcode("[wpv-post-field name='_VenueState' id='".$current_event_venue."']");
$venue_province = do_shortcode("[wpv-post-field name='_VenueProvince' id='".$current_event_venue."']");
$venue_zip = do_shortcode("[wpv-post-field name='_VenueZip' id='".$current_event_venue."']");
$venue_country = do_shortcode("[wpv-post-field name='_VenueCountry' id='".$current_event_venue."']");
return $venue_address.' '.$venue_city.' '.$venue_state.' '.$venue_province.' '.$venue_zip.' '.$venue_country;
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
Next, I also added "venue_address_custom" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
2. After that, I was able to show this address on the map, using the "address" attribute and the new shortcode in the map marker shortcode:
( ref: https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#wpv-map-marker )
[wpv-map-marker map_id="map-2" marker_id="marker-1" address="[venue_address_custom]"][/wpv-map-marker]
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar
Thanks Waqar, that's worked perfectly! Much appreciated