Skip Navigation

[Resolved] Should I add another custom post type to distinguish maps markers

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

Problem:
The user is using a map to display a custom post type posts with a custom marker. He would like to add similar posts and wonders if he needs to create a new custom post type and customize the marker.

Solution:
You can customize the marker for multiple post types or for the same post type. In this ticket, we used the solution to have another custom post type.

Relevant Documentation:

This support ticket is created 4 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.

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.

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: Africa/Casablanca (GMT+01:00)

This topic contains 9 replies, has 2 voices.

Last updated by perryA 4 years ago.

Assisted by: Jamal.

Author
Posts
#1583275

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.

#1583277

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

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.

#1583985

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)?

#1585071

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

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.

#1585099

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]

#1585699

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

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?

#1585813

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

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/

#1585913

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).

#1586591

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

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

#1586647

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.