Skip Navigation

[Resolved] How to display a custom map marker which is added as a term field

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

Problem:

The issue here is that the user has a CPT, however they stored their custom map markers in a Taxonomy custom field and wanted to display these custom markers on a map for their respective posts.

Solution:

I would recommend having a look at the response here.
https://toolset.com/forums/topic/how-to-display-a-custom-map-marker-which-is-added-as-a-term-field/#post-1225464

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

This topic contains 18 replies, has 2 voices.

Last updated by Craig 3 years, 6 months ago.

Assigned support staff: Shane.

Author
Posts
#1225288

I have a CPT called Businesses and within that I have a Taxonomy called Sectors (of which there are 4). I would like to plot all business on a map and have it working fine, all except the custom markers.

I created a Custom Term Field for the markers called "map-marker" (image field) and have uploaded a different custom marker for each sector. I have tried multiple methods to try and pull the correct marker for each Business, but can't seem to get the custom markers to load.

[wpv-map-render map_id="all-businesses" map_height="700px" draggable="off" scrollwheel="off" double_click_zoom="off" map_type_control="off" street_view_control="off" marker_icon="[wpv-taxonomy-field name='wpcf-map-marker']"][/wpv-map-render]

Is this the best way of approaching what I am trying to achieve? Or is there a better way?

#1225313

Shane
Supporter

Languages: English (English )

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

taxonomy terms.PNG

Hi Craig.

Thank you for contacting our support forum.

To get this correctly your custom marker is stored within the taxonomy term's custom field ? Correct?

If so then you will need to create a taxonomy view that will list out the current term of the post being displayed. On that taxonomy view you will need to add a taxonomy term filter. See Screenshot

In the loop output editor of that view you will add the shortcode for the custom field that has the url for the marker.

Example

[types termmeta='marker' output='raw'][/types]

Finally you are going to ensure that the option "Disable the wrapping DIV around the View" is checked.

Once all that is completed you will now insert the view you've created in the marker option section.

Example


[wpv-map-marker map_id='map-2' marker_id='marker-2' marker_icon='[wpv-view name="my-tax-view"]' marker_field='wpcf-location'][/wpv-map-marker]	[wpv-items-found]


If you notice for the marker_icon attribute i've added the view here as this view will provide the url for the marker icon.

Please let me know if this helps.
Thanks,
Shane

#1225368

HI Shane,

Thank you for the detailed response. I now understand the logic behind creating a secondary view to get the term field and then inserting that view into the marker_icon to use the URL from the term field.

However, I am using the view on the homepage of the site, so there are no posts, and the page isn't an archive, so setting the filter as you suggested to "Set by the page where this View is shown" doesn't work.

Is there another way to achieve this?

Kind regards,
Craig

#1225412

Shane
Supporter

Languages: English (English )

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

Hi Craig,

So for the map, what exactly are you displaying on the map itself. This might clue me into making a better recommendation.

Are you displaying post locations on the map or just the taxonomy terms location on the map.

Please let me know.

#1225417
2019-04-03_19-38-38.png
2019-04-03_19-32-53.png
2019-04-03_19-30-42.png

Hi Shane,

I have uploaded a few images to try help explain what I am trying to achieve…

The visual of the map shows what I would like to achieve, and the "Sector" Taxonomy List shows that I have uploaded a custom marker for each "Sector".

Each "Sector" will have multiple "Businesses", and each business within that Sector should have the same coloured Map Marker.

I hope that makes sense. If not, I will upload my localhost site to a publicly available URL for you to see.

Best,
Craig

#1225438

Shane
Supporter

Languages: English (English )

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

Hi Craig,

Thanks for the screenshots.

Yes this was able to assist me, now I see exactly what you want to achieve.

The map markers, they are stored in the custom field of that post correct? I see them under the Map Marker column.

Please let me know.
Thanks,
Shane

#1225440
2019-04-03_20-16-02.png

Hi Shane,

The Map Markers are stored in a Custom Field in each Sector Taxonomy. If I stored them in the actual post, would I not have to add the correct marker in each Business individually?

Kind regards,
Craig

#1225446

Shane
Supporter

Languages: English (English )

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

Hi Crag,

I fully understand the context now.

This display is going to be a little complex because we are going to need 2 views.

The first view to create was the one that I named above which will have the marker information. So in this view here
https://toolset.com/forums/topic/how-to-display-a-custom-map-marker-which-is-added-as-a-term-field/#post-1225313

Instead of have the marker data be


[wpv-map-marker map_id='map-2' marker_id='marker-2' marker_icon='[wpv-view name="my-tax-view"]' marker_field='wpcf-location'][/wpv-map-marker]  [wpv-items-found]

We will have it as


[wpv-map-marker map_id='map-2' marker_id='marker-2' marker_icon='[types termmeta="marker" output="raw"][/types]' marker_field='wpcf-location'][/wpv-map-marker] 

Notice the difference in the marker_icon section.

So the next we need to set the filter to "set by current post".

Next we create a view that will list out the businesses. No this view can be empty because we will only need it to tell which taxonomy to display.

So just add the first view you created into this one and it should populate the map with the correct markers.

Thanks,
Shane

#1225454

Hi Shane,

I am a bit confused… so I now have 3 views…

View 1 – All Businesses Location Map (Post Type = Businesses, Taxonomy Filter = Select posts with taxonomy: Sectors the same as the page where this View is shown)

[wpv-layout-start]
	[wpv-items-found]
	[wpv-map-render map_id="all-businesses" map_height="700px" scrollwheel="off" double_click_zoom="off" map_type_control="off" street_view_control="off"][/wpv-map-render]
	<!-- wpv-loop-start -->
	<wpv-loop>
      [wpv-map-marker map_id='all-businesses' marker_id='marker-[wpv-post-id]' marker_icon='[types termmeta="marker" output="raw"][/types]' marker_field='wpcf-location'][/wpv-map-marker]
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

View 2 – Get Current Sector Map Marker (Taxonomy = Sectors, Taxonomy Term Filter = Taxonomy is set by the page where this View is inserted)

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
		[types termmeta="map-marker" output="raw"][/types]
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

View 3 – List of Businesses (Post Type = Businesses)

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

I have tried various combinations, but still can't get it to work.

#1225464

Shane
Supporter

Languages: English (English )

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

Hi Craig,

Sorry for the confusion but since seeing the screenshots I thought of the best way of doing this.

So in summary we will only have 2 views.

View 1:
Taxonomy view (Sectors view) has the filter for Taxonomy Term set by current post.
In the taxonomy view. The only this that will be in the view is the marker data.

       [types termmeta="map-marker" output="raw"][/types]

View 2:

Your list of business view as you currently have it, except that for the marker data you will have this.


[wpv-map-marker map_id='all-businesses' marker_id='marker-[wpv-post-id]' marker_icon='[wpv-view name='my-tax-view']' marker_field='wpcf-location'][/wpv-map-marker]

This should get you up and running. I realise that I made an error in my previous post but you should Only need 2 views and outline them as I have above.

Please let me know if you are encountering any issues.

Thanks,
Shane

#1225496

Hi Shane,

I have uploaded a copy of the website as it stands to hidden link and created login credentials for you.

Would you be so kind as to take a quick look and see where I am going wrong?

I have tried various combinations of what you suggested, but I always see just the one marker, when there should be 4 in total, one from each sector.

Kind regards,
Craig

#1225875

Shane
Supporter

Languages: English (English )

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

Hi Craig,

I tried to access the site but I'm getting a 403 forbidden error on my end.

Perhaps I need to add some information to my host file to access the site ?

Please let me know.

Thanks,
Shane

#1225879

Hi Shane,

My bad, sorry. The URL should be hidden link

#1225885

Shane
Supporter

Languages: English (English )

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

Hi Craig,

Should be working now.

The only step that you did incorrectly was to add the filter to this view hidden link

Then you added the incorrect view as the marker_icon attribute.

I've corrected this and the proper marker info should be.
[wpv-map-marker map_id='all-businesses' marker_id='marker-[wpv-post-id]' marker_icon='[wpv-view name="get-current-sector-map-marker"]' marker_field='wpcf-google-map-location'][/wpv-map-marker]

Please let me know if this helps.
Thanks,
Shane

#1225907

Hi Shane,

Thanks for that, but I'm not seeing any difference when I load the map on the homepage – hidden link

It is still only showing one marker and it is the default marker, not one of the custom ones.

Best,
Craig