Skip Navigation

[Resolved] Display Map on posts where the address is stored on term meta

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

Problem:
Posts have a location taxonomy assigned, and the location terms have an address stored as term meta. When Viewing a post, how to display a map of the location?

Solution:
Create a View to display the location taxonomy terms and include a Query Filter to set the term according to the page where the View is inserted (which will be the visited post).

Then create a map in the View output following the normal guidelines, with the marker coming from the term address field.

Insert the View in the template for posts.

Relevant Documentation:
https://toolset.com/documentation/user-guides/maps/

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

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by andrei-laurentiuP 5 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#1204186

I have created multiple custom taxonomies (e.g. each continent) with child taxonomies (i.e. each country) for which I define an address as custom field for taxonomy. So user would select the country in the CPT post form (e.g. France, Canada, or whatever by clicking/selecting checkboxes/box lists with multiple selection in a post form) for these selections to later appear on a map belonging to the CPT layout when viewed by anyone (public).

So, if I create the layout and if I am using the map + marker inside the layout, I need to provide an id for the taxonomy address, which would be against the purpose since this id should be the one the user has selected, not the one that I define in the layout (e.g. if I insert a map with a marker and I provide an id for 'Algeria' let's say, all CPT will show the map with Algeria and not what the user/users has/have selected in the post form)
If I try to create the map in a Taxonomy View Display, then all the addresses stored in the taxonomy will appear everywhere.

Is there any way to filter which taxonomies are displayed, so that only the ones selected by the user in the post form will appear on the map? If there is no shortcode for this, I would need a way/function to retrieve multiple taxonomy IDs as selected by user and use them as IDs for the markers, or what would your suggestion be?

Thank you!!!

#1204544

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Let me see if I have got this right.

Users will publish posts, and they can assign terms to that post from various taxonomies (e.g. continent, country etc.).

The taxonomy terms have an address term meta field.

You then want to display a map with markers for any term assigned to the post where the addresses come from the term meta.

Is that correct?

#1204632

Thank you Nigel, yes, that is correct. For any term assigned by the users.

#1205492

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2019-02-25 at 10.58.20.png

OK, I assume the place to display this map is when viewing the post the users created.

So you create a View to display your taxonomy terms (in the Content Selection choose taxonomy, and then the particular taxonomy with the address term fields).

You need to insert a Query Filter to set the term according to the page where the View is inserted (which will be the post created by the user), see screenshot.

Otherwise you follow the normal steps to create a map with markers using this View, with the marker addresses being provided by term meta instead of post meta. See https://toolset.com/documentation/user-guides/display-on-google-maps/displaying-markers-on-google-maps/#displaying-a-map-with-a-list-of-markers-coming-from-a-view for an overview.

You then edit the Content Template for the single post type that users will be creating where you want the map to appear, and insert this new View into the template.

If you get stuck with anything, do let me know.

#1205605

Thank you very much, Nigel! Case closed! 😀