Skip Navigation

[Resolved] Adding map in template file

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 18 replies, has 2 voices.

Last updated by CraigS3893 4 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1505161

Hi,
My client hidden link requires a new map page showing the locations of all the restaurant, cafe, and shops posts (Types CPTs) that she's added to her site.

I've added the Toolset Maps plugin and enabled her API key. The new Address field is working on each custom post as it should but I need a bit of help outputting the map in a new template file.

I don't use Views, I'm still doing everything programatically in the template files, so need to know:

1. How to output a map showing ALL the markers added for Restaurants, Cafes and Shops CPTs. These markers should (on click) display a tooltip/box containing further info and a link to the single post .

2. How to customise the marker icons (if possible).

Any help would be much appreciated.

Cheers
Craig

#1505399

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Craig,

Thank you for getting in touch.

You can actually do this by following the instructions in the link below.
https://toolset.com/documentation/user-guides/maps/display-on-google-maps/displaying-markers-on-google-maps/

This should be able to guide you through the process.

Thanks,
Shane

#1505433

Hi Shane
thanks, but I don't use Views - I need to do this in the template file.

#1505443

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Craig,

In this case you are going to have to use the do_shortcode() function for wordpress.
https://developer.wordpress.org/reference/functions/do_shortcode/

Is the page that you are doing this on rendering a list of posts or is it a single post being rendered?

Please let me know.
Thanks,
Shane

#1505469

Hi Shane
The page needs to display a map showing the location markers for all the Restaurants, Cafes, and Shops posts. Each marker's popup box should contain the post title and a link to the relevant single post. Is this possible?

If so, how do I get the map shortcode? (I know how to use the do_shortcode part) - it needs to display in a new template file using PHP / loop to show all the markers?

#1505523

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Craig,

Thank you for the information.

Any reason why views isn't use to do this ?

However using the do_shortcode you will need to pass everything into the shortcode manually. So you would need to pass the id's into the marker shortcode manually as well.

echo do_shortcode("[wpv-map-render map_id='map-6'][/wpv-map-render]);
");

/*------inside loop----*/
$post_id = get_the_ID();

$address = do_shortcode("[types field='address' item="'.$post_id.'"]");

echo do_shortcode("[wpv-map-marker map_id='map-6' marker_id='marker-6' marker_field="'.$address.'"][/wpv-map-marker]");

Please try this and let me know if this helps.
Thanks,
Shane

#1505527

Hi Shane
Thanks. I've been using Types for years and have always done things programatically using render_fields - still haven't got around to trying out Views.

I'll try this. Will let you know how it goes...

#1505537

Hi
I'm guessing this solution still requires the use of Views, as all it's doing is outputting the un-rendered shortcodes.

Output is here: hidden link

My template code is:

<?php echo do_shortcode("[wpv-map-render map_id='map-6'][/wpv-map-render]);"); ?>

<?php
$args = array(
'post_type' => array( 'cafe', 'restaurant', 'shop'),
'category_name' => 'review',
'post_status' => 'publish'
);
$wp_query = null;
$wp_query = new WP_Query($args);
if( $wp_query->have_posts() ) {
echo '';
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

<?php

/*------inside loop----*/
$post_id = get_the_ID();

$address = do_shortcode(" [types field='address' item=" .$post_id. "] ");

echo do_shortcode("[wpv-map-marker map_id='map-6' marker_id='marker-6' marker_field=" .$address. "][/wpv-map-marker]");

?>

<?php
endwhile;
} ?>

<?php wp_reset_query(); ?>

Isn't there a way to output the map using regular PHP / types_render_field etc. ?

#1505779

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Craig,

I forgot to mention that since the map shortcode is a view shortcode then the views plugin is required to use the map.

I was under the impression that you had our views installed and activated but not using it to create the templates.

Thanks,
Shane

#1506705

Hi Shane
So it's not possible to do this programatically?

#1507133

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Craig,

Unfortunately no it is not since the shortcode is linked to our views plugin.

Is there a specific reason why you're not able to have views installed ?

Thanks,
Shane

#1507225

No, other than the fact I've never used it and have been happy doing things in the template files - I just prefer it that way as I'm not keen on core functionality being stored in the database - I'd rather this was in the PHP templates, but no worries.

Suppose it's an opportunity for me to try out Views!

#1507237

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Craig,

Yes this would be a really good opportunity as you say to try out views.

It would make creating your templates far easier, as you would still have the ability to you use HTML in the editor to still customize your content.

Thanks,
Shane

#1512877

Hi Shane
Okay I've installed Views and tried following the instructions but my map is displaying with no markers.

Can I provide you with login info so you can take a look and let me know where I'm going wrong please?

#1512915

Scratch that. I was inserting a Map on the page rather than the View I'd created. All working now.

Thanks for your help on this.