Support Forum
Hi,
I have Posts (default Post type) and Sources (custom Post type).
A Post can have multiple Sources and a Source can be used for multiple Posts (many to many relationship).
In the relationship I want to describe in a field why they are related. Because I can't add custom fields to a MB relationship, I thought to create another Custom Post type depicting the relationship between a Post and a Source: Post2Source. This way I can add a custom field to this Relationship. I've created 2 MB relationships for this:
-Post-Post2Source: this is the 1 to many relationship from Post to Post2Source
-Source-Post2Source: this is the 1 to many relationship from Source to Post2Source (a Post2Source record can only have 1 Source record)
I've set this up and it holds all content and relationships.
Now I want to create a MB View that displays a Post with its Sources. So I have to traverse the Post to the Sources via the Post2Source. I managed to display the Post content with the Post2Source content with the following code:
<main>
<article>
<h2>
{{ post.title }}
</h2>
{{ post.content }}
</article>
<section class="sources">
{% set relationship = attribute( relationships, 'post-post2source' ) %}
{% for post in relationship.to %}
{{ post.title }}
<p>
{{ post.content }}
</p>
{% endfor %}
</section>
</main>
How do I retrieve the content of the Source? So in the existing "for loop" above, how can I query in the current retrieve 'Post-Post2Source' the related Source content? I tried to add another "for loop" using the relationship "Source-Post2Source", but that doesn't work. Apparently the focus is kept on the Post and doesn't change the focus to Post2Source, so it doesnt give any result.
Is it possible in MB views to go from the Post to Post2Source to Source content in a query?
Kind regards, Henri