Show map field in related post

Support MB Views Show map field in related postResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #22898
    Eddie the EagleEddie the Eagle
    Participant

    I 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/vl8d0i

    What is it that I am doing wrong?

    #22899
    Long NguyenLong Nguyen
    Moderator

    Hi 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/#arguments

    #22903
    Eddie the EagleEddie the Eagle
    Participant

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

    #22908
    Long NguyenLong Nguyen
    Moderator

    Hi Eddie,

    Please use the field ID for the first argument of the helper function. It might be osm_karte for 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.

    #22913
    Eddie the EagleEddie the Eagle
    Participant

    Hi Long,

    That was the solutions, many thanks to you and the super service.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.