Skip Navigation

[Resolved] Display a map based on taxonomy field in custom post type

This thread is resolved. Here is a description of the problem and solution.

Problem:

Display term's address field in Google map.

Solution:

You can use classic editor to setup the map and marker shortcode, for example:

https://toolset.com/forums/topic/display-a-map-based-on-taxonomy-field-in-custom-post-type/#post-2287513

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/

This support ticket is created 3 years 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.

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

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 7 replies, has 2 voices.

Last updated by Arno 3 years ago.

Assisted by: Luo Yang.

Author
Posts
#2287033

Hi,

I have a custom post type which has a taxonomy with a custom Address field. I have a view to filter on the post types and need a map to display the addresses of the terms of the selected posts (one address for each post).

The view works but I have trouble with the map. I understand I need the legacy editor as it can't be done in blocks yet. I created a taxonomy view with the query filter set to "Select taxonomy terms whose parent is the value set by the parent view.".

I don't know how to proceed. All courses (https://toolset.com/course-lesson/) I read so far are with the block editor only. The programmer reference (https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/) is useful but I miss complete examples, with all the steps and markup explained. Where can I find that?

#2287347

Hello,

Please share your website credentials in below private message box, also point out the problem page URL and view URLs, I need to test it in a live website, thanks

#2287455
actual location in taxonomy term.jpg
wrong location frontend.jpg

Hi Luo,

Issue 1:
The custom post type Activities is using the taxonomy TaxLocations1, which has an Address field called "Where is it".

The frontend page is hidden link. The view shows the Activities and allows filtering on the taxonomy. That works fine. Under Toolset - Views I have created the view "Locations from tax all results". I'm using this in the "Fields and Text" block in the view loop.

I need a full example on how to proceed to display the addresses on a map. I was only able to find examples based on an address field in the post rather than the taxonomy, and it's all blocks based. Where are the legacy examples that I need for stuff like this? Step by step with the full markup, that would be really helpful.

Issue 2:
The view shows buttons that link to the individual Activity posts. The template for a single Activity includes a map. This basically works, but for 1 out of 3 activities it shows the wrong location: it points to Geneva in the USA but I manually selected a location in Geneva Switzerland. Please see the screenshots.

Many thanks!

Arno

#2287477

Thanks for the details, I can login into your website, will update here if find anything

#2287513

I have done below modifications in your website:
1) Edit the taxonomy view "Locations from tax all results":
hidden link
- Change the filter to:
Taxonomy is set by the current post
- In view's loop, display the marker shortcode as below:
[wpv-map-marker map_id='map-21' marker_id='marker-[wpv-taxonomy-id]' marker_termmeta='wpcf-where-is-it'][wpv-taxonomy-link][/wpv-map-marker]

2) Edit the problem page
hidden link
Display the map shortcode as below:
[wpv-map-render map_id="map-21"][/wpv-map-render]

Test it in frontend:
hidden link
It works fine,

3) Edit the content template "Template for Activities"
hidden link
Replace the map block with above taxonomy view shortcode + map shortcode:

[wpv-view name="locations-from-tax-all-results"]
[wpv-map-render map_id="map-21"][/wpv-map-render]

Test it in frontend:
hidden link

It works fine too, please check if it is fixed, thanks

#2287617

Thanks a lot. That works fine and I understand the concept. I would not have been able to figure this out myself. I didn't know that basically all data selection and even the map ID selection is done in the legacy taxonomy view. Once all of that works, it's only a matter of using the right short codes on-page. The markup for wpv-map-marker makes sense when seeing it, but it's hard to come up with that for Toolset beginners.

So there is no documentation?

Will all of this be easier, and blocks based, in the future? And when?

Thanks again!

#2287621

The document for classic editor was removed, and replaced with Blocks editor, we are improving features of Blocks editor, but there isn't any ETA for it, currently, please follow our document to setup the map and marker shortcodes:
https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/

#2288957

Ok, thanks, I will submit new threads if the programmer reference is not clear.