Tell us what you are trying to do? - I'm trying to display map markers from the address field on Locations (child post) when someone searches for Physicians (parent). I'd like to display all map marker locations by default.
The site has Physicians (parent) and Locations (child) in a many to many relationship. Physicians can belong to multiple locations and locations can apply to multiple Physicians. The Address field to display map markers is under Locations (child)
Is there any documentation that you are following? - Yes, I've read every support topic that relates as well as all the Toolset Maps documentation. This - https://toolset.com/lesson-placement/lesson-placements-1622939-1620853/ - and also this support request - https://toolset.com/forums/topic/showing-parent-markers-on-child-archive-map/. I created a view for the search, then built a child view to display all the map markers by location, then nested the child view in the parent view but still no markers.
Is there a similar example that we can see? This page is working correctly - hidden link - but the query is already in locations so the map markers just show up as locations has the default Address field. The map markers will be the same on both maps.
What is the link to your site? hidden link
Hello,
Toolset Blocks/Views plugin is using WordPress built-in class WP_Query to query posts, so you can filter the results by custom fields of current post type.
For example, if you are querying Physicians posts, you can filter the results only by custom fields of Physicians post type, you can not filter the results by custom fields of another post type(location).
You might consider other workaround, for example, move the custom field "address" into post type "Physicians", and setup it as a repeating field:
https://toolset.com/documentation/customizing-sites-using-php/displaying-repeating-fields-one-kind/
So you can setup a post view:
- Query "Physicians" posts
- Filter the result by custom fields of post type "Physicians", including "address" field
Hi Luo - I don't need to filter by address. I just need to display the address from the address field of the child post on a map on the same page. Is that possible?
I assume we are talking about this page:
hidden link
Yes, it is possible, you just need to put the marker shortcode [wpv-map-marker ...] into the child post view, see our document:
https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#wpv-map-marker
If you need more assistance for it, please provide your website credentials in below private message box, I can setup a demo for you.
Hi Luo - Yes, that page.
I've read that document but it's not clear to me where the marker shortcode should be placed in the child post view and even less clear where to place the child view in the parent view.
How do I send you credentials using a 'private message box'?
There is no obvious way or reference to this.
This box is not private as I can view it without being logged in.
This is the parent view:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<ol class="wpv-loop js-wpv-loop">
<wpv-loop>
<li>[wpv-post-body view_template="loop-item-in-search-providers"]</li>
</wpv-loop>
</ol>
<!-- wpv-loop-end -->[wpv-view name="search-providers-locations"]
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]<h4 style="text-align:center;margin:40px auto;">No offices within your search. <a href=".">Click here</a> to view all offices</h4>[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
Here is the child view
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-map-marker map_id='map-8' marker_id='marker-[wpv-post-id]' marker_field='address'][/wpv-map-marker]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]<h4 style="text-align:center;margin:40px auto;">No offices within your search. <a href=".">Click here</a> to view all offices</h4>[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
If you need site access please include instructions for creating a private message box to send them to you.
Thank you for your help!
I can get your website credentials from the emails, and have done below modifications in your website:
1) Edit the child post view "Search Providers Locations":
hidden link
a) In section "Query Filter", change the filter to:
Select posts in a Physicians at Locations relationship that are a related to the current post in the loop.
b) In section "Loop Editor", change the marker shortcode from:
[wpv-map-marker map_id='map-8' marker_id='marker-[wpv-post-id]' marker_field='address'][/wpv-map-marker]
To:
[wpv-map-marker map_id='map-8' marker_id='marker-[wpv-post-id]' marker_field='wpcf-address'][/wpv-map-marker]
You need to add "wpcf-" prefix before the custom field slug, more help:
https://toolset.com/documentation/customizing-sites-using-php/functions/
when you are accessing custom fields through native WordPress functions, you need to prepend the wpcf- prefix to the slug
enable option "Disable the wrapping DIV around the View"
2) edit the content template of parent post view:
hidden link
at the bottom, add a view block, chose above child post view
Please test again, check if it is fixed, thanks
Hi Luo - I was really close - thank you for your support. Yes the markers appear on the map now.
Final question, how do I get the location name and address to appear when a user clicks on a marker? I used the built in option in the map, but choosing fields that aren't in the current post doesn't seem to work. I also added wpcf prefix when trying to connect those fields with no luck. Thanks!
You can follow the document I mentioned above to customize the marker popup:
https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#wpv-map-marker
I have setup a demo in your website:
Edit the child post view:
hidden link
Change the marker shortcode to:
[wpv-map-marker map_id='map-8' marker_id='marker-[wpv-post-id]' marker_field='wpcf-address']
Location title:[wpv-post-title] <br />
location address: [types field='address'][/types]
[/wpv-map-marker]
For your reference.
Excellent explanation - that makes a lot of sense. Everything is working now as it's supposed to be.
Thank you for your help!