Show map field in related post
- This topic has 4 replies, 2 voices, and was last updated 5 years ago by
Eddie the Eagle.
-
AuthorPosts
-
November 18, 2020 at 1:08 PM #22898
Eddie the Eagle
ParticipantI have connected 2 custom post types (events, map) to the MB_Relationships_API After that I created a view for the CPT events detail view and for maps also.
Now I want to show the venue in the detailed view of the event. The field longitude and latitude is displayed without problems, the corresponding map unfortunately not.
No errors are shown in the console. Here is my code in the detail view of events:
<h2> {{ post.title }} </h2> <div class"veranstaltung-datum"> {{ post.date | date( 'j. F, Y H:i' ) }} Uhr </div> <div class"veranstaltung-text"> {{ post.wysiwyg_veranstaltung }} </div> <div class"veranstaltung-karte"> {% for post in relationships.veranstaltung_to_karte.from %} {{ post.osm_karte.latitude }},{{ post.osm_karte.longitude }} {{ post.osm_karte.rendered }} {% endfor %} </div>Screenshot detail view events: https://prnt.sc/vl8cka
Screenshot detail view maps: https://prnt.sc/vl8d0iWhat is it that I am doing wrong?
November 18, 2020 at 3:23 PM #22899Long Nguyen
ModeratorHi Eddie,
The View does not support to show the map in the custom query, only show by using the PHP code. So you can use the helper function via the proxy
mb.:{% for post in relationships.veranstaltung_to_karte.from %} {{ post.osm_karte.latitude }},{{ post.osm_karte.longitude }} {{ mb.rwmb_meta( post.osm_karte, '', post.ID }} {% endfor %}For more information, please follow the documentation:
https://docs.metabox.io/extensions/mb-views/#running-php-functions
https://docs.metabox.io/fields/osm/#template-usage
https://docs.metabox.io/rwmb-meta/#argumentsNovember 19, 2020 at 1:18 AM #22903Eddie the Eagle
ParticipantThank you very much for your help. I put the following code inside my view:
{% for post in relationships.veranstaltung_to_karte.from %} {{ post.osm_karte.latitude }},{{ post.osm_karte.longitude }} {{ mb.rwmb_meta( 'post.osm_karte', '', post.ID) }} {% endfor %}But the output is the same as before.
November 19, 2020 at 9:40 AM #22908Long Nguyen
ModeratorHi Eddie,
Please use the field ID for the first argument of the helper function. It might be
osm_kartefor your case.{{ mb.rwmb_meta( 'osm_karte', '', post.ID) }}Check the field ID in your code or in the Builder https://share.getcloudapp.com/E0u456BB.
November 19, 2020 at 1:34 PM #22913Eddie the Eagle
ParticipantHi Long,
That was the solutions, many thanks to you and the super service.
-
AuthorPosts
- You must be logged in to reply to this topic.