Skip Navigation

[Resolved] Customise map markers using post relationships

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

Problem:

I have a many-to-many post relationship between Students and Routes.

What I would like to do is be able to differentiate between the Students on a given route, according to the schools they attend.

For example, on Route A there are 20 students that attend School 1 and twenty students that attend School 2. I would like to see all forty students on a map, with one colour marker for School 1's students and a different colour for School 2's students.

Solution:

I suggest you try with a nested view, for example:

https://toolset.com/forums/topic/customise-map-markers-using-post-relationships/#post-1200798

Relevant Documentation:

This support ticket is created 6 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 4 replies, has 2 voices.

Last updated by Greig Neilson 6 years ago.

Assisted by: Luo Yang.

Author
Posts
#1200753

I have a many-to-many post relationship between Students and Routes.

I can display all of the students on a map and I can filter these students according to the school they attend.

I can also display all of the students on a map and filter them by route.

What I would like to do is be able to differentiate between the Students on a given route, according to the schools they attend.

For example, on Route A there are 20 students that attend School 1 and twenty students that attend School 2. I would like to see all forty students on a map, with one colour marker for School 1's students and a different colour for School 2's students.

#1200798

Hello,

I suggest you try with a nested view, for example:
1) Add a custom image field "marker-icon" to post type "Routes",
edit each "Routes" post, setup different "marker icon" image

2) Create a post view "routes-view":
- query "Routes" posts
- in section "Loop Editor", display below child post view's shortcode with a custom attribute "marker-icon", for example:
[wpv-view name="child-student-view" mark-icon='[wpv-post-field name="wpcf-marker-icon"]']

It will pass the "marker-icon" field value to child post view

3) Create a post view "child-student-view":
- query Students posts
- filter by post type relationship
- in section "Loop Editor", you can get the mark-icon value with shortcode [wpv-attribute], like this:
[wpv-attribute name="mark-icon"]

And use it as the marker's icon

More help:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
https://toolset.com/documentation/user-guides/maps-shortcodes/#wpv-map-marker

#1201315

Hi Luo

I'm sorry but I find your instructions really confusing.

In 2) I can't tell whether there are two shortcodes within the view loop or one.
Right now I have two lines, one for the child view and one for the marker icon:
[wpv-view name="display-route-assignment-on-a-map-working"]
[wpv-attribute name="wpcf-route-marker-icon"]

In 3) you mention a filter, but I don't want to filter any records by relationship, I want to display them all.

My nested view now looks like this:
<!-- wpv-loop-start -->
[wpv-map-render map_id="map-7" map_height="1000px" spiderfy="on"]
<wpv-loop>
[wpv-map-marker map_id='map-7' marker_id='marker-6' marker_icon='[wpv-attribute name="route-marker-icon"]' marker_field='wpcf-student-address']
[wpv-post-body view_template="loop-item-in-display-route-assignment-on-a-map-working"]
[/wpv-map-marker]
</wpv-loop>
[/wpv-map-render]
<!-- wpv-loop-end -->

I've done my best to follow your instructions but I feel that that require a base level of knowledge that I don't have.

Your advice about a custom field with an image works perfectly. I can even make this image display in the map marker's information panel by using this shortcode: [types field='route-marker-icon' item='@route-and-student.parent' title='%%TITLE%%' alt='%%ALT%%' size='full'][/types]

I just can't get that ^^ value into the Map Marker shortcode in the Loop.

Where to next?

#1201526

Since you can get the "route-marker-icon" image correctly with Types shortcode, then you can get the image URL with attribute url="true", for example:
[types field="route-marker-icon" item="@route-and-student.parent" url="true" size="full"][/types]

And use it in the marker shortcode, like this:

[wpv-map-marker map_id='map-7' marker_id='marker-6' marker_field='wpcf-student-address' marker_icon='[types field="route-marker-icon" item="@route-and-student.parent" url="true" size="full"][/types]']

More help:
https://toolset.com/documentation/customizing-sites-using-php/functions/#image
attributes
true=output the url of the image instead of the html img tag.

#1201529

My issue is resolved now. Thank you!