The relationship in View thru Shortcode doesn't get shown

Support MB Views The relationship in View thru Shortcode doesn't get shownResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #43940
    EddyPiVEddyPiV
    Participant

    Hi,

    I have a relationship from client to country. Works nicely, also in View / Singular.
    It's just that in the View / Shortcode I can't get the country to be shown.

    {% set args = { post_type: 'fan', posts_per_page: -1, orderby: 'title', order: 'asc' } %}
    {% set posts = mb.get_posts( args ) %}
    
    <table>
    <tbody>
    <tr>
    	<th><strong>Fan ID</strong></td>
    	<th><strong>Name</strong></td>
    	<th><strong>Country</strong></td>
    	<th><strong>Action</strong></td>
    </tr>
    {% for post in posts %} 
    	<tr>
    		<td>{{ post.title }}</a></td>
    		<td>{{ post.name }}</td>
    		<td>{% set relationship = mb.attribute( relationships, 'fan-countrydetails' ) %}
    		{% for post in relationship.to %}
    			{{ post.post_title }}
    			{{ field }}
    		{% endfor %}</td>
    		<td class="middle"><a href="https://staff.ladyfatale.com/fan-details/?rwmb_frontend_field_post_id={{ post.ID }}" rel="">[icon name="pencil-alt" style="solid" class="middle" unprefixed_class="middle"]</a>   <a href="https://staff.ladyfatale.com/fan/{{ post.title }}" rel="">[icon name="eye" style="regular" class="middle" unprefixed_class="middle"]</a></td>
    	</tr>
    {% endfor %}
    </tbody>
    </table>

    Can you please advise?
    Thanks!

    #43944
    PeterPeter
    Moderator

    Hello,

    You can use the sample code below to get relationship posts in a loop:

    {% for post in posts %}
    
        {# get the country post #}
        {% set country_args = { post_type: 'countrydetails', relationship: { id: 'fan-countrydetails', to: post.ID } } %}
        {% set country_posts = mb.get_posts( country_args ) %}
        {% for country_post in country_posts %}
            {# output the country post and other info #}
            {{ country_post.post_title }}
        {% endfor %}
    
    {% endfor %}
    #43952
    EddyPiVEddyPiV
    Participant

    Hi Peter,

    With your help I managed to get it working.

    Thanks a lot, regards.

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