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?