Support Forum
I want to build a single post view where I show fields from the post type A, B and C. All three post types are connected with each other with mb relations. A has a relation to B and B has a relation to C.
How can I build this view? I tried it this way:
Info A: {{ post.title }}
{% for post in relationships.A_B.from %}
Info B: {{ post.title }}
{% for post in relationships.B_C.from %}
Info C:
<img src="{{ post.thumbnail.medium.url }}" width="{{ post.thumbnail.medium.width }}" height="{{ post.thumbnail.medium.height }}" alt="{{ post.thumbnail.medium.alt }}" />
{% endfor %}
{% endfor %}
What am I doing wrong? Thanks for your help.
Hi,
Please refer to this topic to traverse multiple related CPTs A > B > C
https://support.metabox.io/topic/traversing-multiple-related-cpts/
Hi Long, thanks for your answer, but I still don't get it. I wrote the following code:
<h1>Wohnungs-Nr.: {{ post.title }}</h1>
{% set hauseingang_args = { relationship: { id: 'relationships.hauseingang_mietwohnung.from, from: post.ID }, nopaging: true, post_type: 'hauseingang' } %}
{% set hauseingaenge = mb.get_posts( hauseingang_args ) %}
{% set gebaeude_args = { relationship: { id: 'relationships.gebaeude_hauseingang.from', from: hauseingang.ID }, nopaging: true, post_type: 'gebaeude' } %}
{% set gebaeuden = mb.get_posts( gebaeude_args ) %}
{% endfor %}
{% endfor %}
And I get the following error:
Fatal error: Uncaught MetaBox\Dependencies\Twig\Error\SyntaxError: Unexpected character "'" in "wohnung" at line 17. in /home/catharina/public_html/wp_trabrennbahn-farmsen-02/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-views/dependencies/Twig/Lexer.php:363 Stack trace: #0 /home/catharina/public_html/wp_trabrennbahn-farmsen-02/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-views/dependencies/Twig/Lexer.php(279): MetaBox\Dependencies\Twig\Lexer->lexExpression() #1 /home/catharina/public_html/wp_trabrennbahn-farmsen-02/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-views/dependencies/Twig/Lexer.php(180): MetaBox\Dependencies\Twig\Lexer->lexBlock() #2 /home/catharina/public_html/wp_trabrennbahn-farmsen-02/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-views/dependencies/Twig/Environment.php(460): MetaBox\Dependencies\Twig\Lexer->tokenize() #3 /home/catharina/public_html/wp_trabrennbahn-farmsen-02/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-views/dependencies/Twig/Environment.php(507): MetaBox\Depende in /home/catharina/public_html/wp_trabrennbahn-farmsen-02/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-views/dependencies/Twig/Lexer.php on line 363
Can you help me any further? Thanks 🙂
Hi,
When using the argument, please use the relationship ID only, don't access the relationship ID via property relationships
or from
{% set hauseingang_args = { relationship: { id: 'hauseingang_mietwohnung', from: post.ID }, nopaging: true, post_type: 'hauseingang' } %}
{% set hauseingaenge = mb.get_posts( hauseingang_args ) %}
<ul>
{% for hauseingang in hauseingaenge %}
<li>Hauseingang: {{ hauseingang.post_title }}</li>
{% set gebaeude_args = { relationship: { id: 'gebaeude_hauseingang', from: hauseingang.ID }, nopaging: true, post_type: 'gebaeude' } %}
{% set gebaeuden = mb.get_posts( gebaeude_args ) %}
<ul>
{% for gebaeude in gebaeuden %}
<li>Gebäude: {{ gebaeude.post_title }}</li>
{% endfor %}
</ul>
{% endfor %}
</ul>
Please check the code carefully https://support.metabox.io/topic/traversing-multiple-related-cpts/#post-32105