Issue displaying several values of relationship on archive page

Support MB Relationships Issue displaying several values of relationship on archive page

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #44053
    MatthiasMatthias
    Participant

    I'm working in Bricks Builder and the integration is really good. I watched the tutorial https://www.youtube.com/watch?v=W4AOlPGBuH8 that was quite helpful.

    The set-up I have (and it is working in general):

    MB:
    - Two CPT 'kurs' (courses) and 'person'
    - MB relationship 'kurs-person'

    Archive page in Bricks Builder:
    - Query loop on CPT 'kurs', displays all courses
    --Some fields like course title and course description
    --Container with query loop on MB relationship 'kurs-person'
    ---Meta data field 'person_name': displays the name of the person in a div.

    But when I have more than one person related to one course the meta data field creates two div. And I want just a comma-separated list in one div.

    Thus, I created a shortcode with MB View which works very well on a single page:

    {% set relationship = attribute( relationships, 'kurs-person' ) %}
    {% set mentorNames = "" %}
    {% for post in relationship.to %}
        {% if mentorNames != "" %}
            {% set mentorNames = mentorNames ~ ', ' %}
        {% endif %}
        {% set mentorNames = mentorNames ~ post.person_name %}
    {% endfor %}
    {% if relationship.to|length == 1 %}
        Mentor: 
    {% else %}
        Mentoren: 
    {% endif %}
    {{ mentorNames }}

    For the archive page I read the documentation (https://docs.metabox.io/extensions/mb-relationships/#post-archive and https://metabox.io/mb-views-how-to-display-relationships/) but I'm still having issues. I fed the content of the doc into several AI like ChatGPT but they didn't come up with a working response.

    In MB View I have now a code like this that is not working.

    {% set archive_query = query %}
    {% set kurs_posts = archive_query.posts %}
    
    {% for kurs in kurs_posts %}
        {% do MB_Relationships_API::each_connected({
            'id': 'kurs-person',
            'from': kurs
        }) %}
    
        {% set mentorNames = [] %}
        {% for person in kurs.connected.kurs_person %}
            {% set mentorNames = mentorNames|merge([person.person_name]) %}
        {% endfor %}
        {{ mentorNames|join(', ') }}
    {% endfor %}

    Any ideas how to achieve the output of several person names related to one course on the course archive page?

    #44056
    PeterPeter
    Moderator

    Hello Matthias,

    I'm not sure if the MB Views works with Bricks to get the post ID of each post in the loop (archive page), but you can refer to the topic below to use the MB Views to create your own archive page and display all "persons" posts that related to a "kurs" post.
    https://support.metabox.io/topic/the-relationship-in-view-thru-shortcode-doesnt-get-shown/

    For further assistance, I recommend contacting Bricks support, they maintain the compatibility with Meta Box on their end.

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