[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.
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?
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.
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.