Now that I have the "Commercial Projects" set up -- I need another post for "Residential Projects". Do I need to duplicate everything I did for the Commercial Projects -- or is there a way I can change the post type to just "Projects" and maybe have a category set up for both Commercial Projects and Residential Projects? I need to be able to have 2 makers types on the map.
You may choose on of the two solutions:
- Different custom post types, sharing some custom fields groups.
- Same custom post type, with a taxonomy.
Then inside your map view, you can use conditional shortcodes on post_type or on a taxonomy to display a different marker for each type of project.
- https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/
- https://toolset.com/documentation/user-guides/maps/maps-shortcodes/#wpv-map-marker
On our reference site, Real Estate Listings, we choose the first option and we customized marker per custom post type(apartment, house, land, etc.), check how we use [wpv-post-type] inside the marker_icon attribute:
[wpv-map-marker map_id="map-4" marker_id="marker-[wpv-post-id]" marker_field="wpcf-property-location" marker_icon="<em><u>hidden link</u></em>;.png" current_visitor_location="true" map_render="wait"]
Keep in mind, that if you want to show multiple markers on the same map, you must have different marker ids:
This is not correct:
[wpv-map-marker map_id='map-1' marker_id='marker-4' marker_field='wpcf-commercial-address'][/wpv-map-marker]
This is correct:
[wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]' marker_field='wpcf-commercial-address'][/wpv-map-marker]
I hope this helps. Let me know if you have any questions.
So for your example using different custom post types -- I created a new custom post type called "Residential Projects"
Do I need to set up a view for Residential Projects? Or do I add the unique marker to the original map view (with the same map ID) I created (Commercial Projects)?
It depends on what do you want! If you want to have two maps, you will definitely need to create another view, on which, the map will have a different id.
If you want to display both custom post types ("Residential Projects" and "Commercial Projects") on the same view/map, just update the "Content Selection" of the view and select both custom post types.
Remember, that ID, for maps, markers, posts, divs, any element, is meant to be unique. That's why I suggested having a unique ID for each marker in my previous replies. Post ID, as an example, is always unique.
So I don't understand how I call for a different post type (Residential Projects). The view seems to be specific to the post you are calling... My thought is that I would duplicate the map marker in the loop and get it to pull from the Residential Projects posts... but I don't see how you do that.
[wpv-layout-start]
[wpv-items-found]
[wpv-map-render map_id="map-1" map_height="400px" marker_icon="//dev.rileypalmerconstruction.com/wp-content/plugins/toolset-maps/resources/images/markers/Hospital-1.png"][/wpv-map-render]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-map-marker map_id='map-1' marker_id='marker-4' marker_icon='hidden link' marker_icon_hover='hidden link' marker_field='wpcf-commercial-address'][wpv-post-body view_template="template-for-commercial-projects"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]
Would you allow me temporary access to your admin area to check this view further? Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
Please let me know which page to check? And which view?
Please confirm that you want to display both custom post types on the same map.
Also, elaborate more on how you want to customize markers? Do you want to use custom markers?
Please check this screenshot, Residential Projects must be added to the view hidden link
Then, there was an error on the markup shortcode, the marker shortcode was not closed with [/wpv-map-marker]. I fixed it.
I also updated marker_id='marker-4' to marker_id='marker-[wpv-post-id]'. As I explained earlier, there must be only one unique id 😉
Now, to distinguish between custom post types and assign a different marker icon per post type, we'll need to use conditional tags, I already added it to the view:
<wpv-loop>
[wpv-conditional if="( '[wpv-post-status]' eq 'commercial-project' )"]
[wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]' marker_icon='<em><u>hidden link</u></em>' marker_icon_hover='<em><u>hidden link</u></em>' marker_field='wpcf-commercial-address'][wpv-post-body view_template="template-for-commercial-projects"][/wpv-map-marker]
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-status]' eq 'residential-project' )"]
[wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]' marker_icon='<em><u>hidden link</u></em>' marker_icon_hover='<em><u>hidden link</u></em>' marker_field='wpcf-commercial-address'][wpv-post-body view_template="template-for-commercial-projects"][/wpv-map-marker]
[/wpv-conditional]
</wpv-loop>
I will let you update the above code to use a different marker, basically, you will need to update "marker_icon" and "marker_icon_hover" for residential projects.
If you have configured the first marker using Toolset interface, create a new view for residential projects and configure a different marker, then go to the code and copy the values for "marker_icon" and "marker_icon_hover" to your current view.
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/
Jamal -- thanks for all the help -- it is much appreciated.
If I understand what you did correctly -- I just need to change the marker icon references to complete the look of the map. But if I preview the map right now (I haven't touched anything since you made changes) -- nothing shows up (no markers).
My apologies, that was my mistake. I used the post status [wpv-post-status] in the condition instead of the post type [wpv-post-type].
I just fixed it on your website and I see that you have implemented a different marker for Residential projects. Check this screenshot hidden link
The updated code is:
<wpv-loop>
[wpv-conditional if="( '[wpv-post-type]' eq 'commercial-project' )"]
[wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]' marker_icon='<em><u>hidden link</u></em>' marker_icon_hover='<em><u>hidden link</u></em>' marker_field='wpcf-commercial-address'][wpv-post-body view_template="template-for-commercial-projects"][/wpv-map-marker]
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-type]' eq 'residential-project' )"]
[wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]' marker_icon='<em><u>hidden link</u></em>' marker_icon_hover='<em><u>hidden link</u></em>' marker_field='wpcf-commercial-address'][wpv-post-body view_template="template-for-commercial-projects"][/wpv-map-marker]
[/wpv-conditional]
</wpv-loop>
All the best.
Jamal
My issue is resolved now. Thank you!