Create a view with information from three different related post types
- This topic has 3 replies, 2 voices, and was last updated 3 years, 1 month ago by
Long Nguyen.
-
AuthorPosts
-
February 26, 2022 at 4:37 PM #34154
Catharina von Hobe
ParticipantI 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.
February 26, 2022 at 10:08 PM #34163Long Nguyen
ModeratorHi,
Please refer to this topic to traverse multiple related CPTs A > B > C
https://support.metabox.io/topic/traversing-multiple-related-cpts/February 27, 2022 at 6:29 AM #34172Catharina von Hobe
ParticipantHi 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 ) %}-
{% for hauseingang in hauseingaenge %}
- Hauseingang: {{ hauseingang.post_title }}
{% set gebaeude_args = { relationship: { id: 'relationships.gebaeude_hauseingang.from', from: hauseingang.ID }, nopaging: true, post_type: 'gebaeude' } %}
{% set gebaeuden = mb.get_posts( gebaeude_args ) %}-
{% for gebaeude in gebaeuden %}
- Gebäude: {{ gebaeude.post_title }}
{% 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 🙂
February 27, 2022 at 1:57 PM #34176Long Nguyen
ModeratorHi,
When using the argument, please use the relationship ID only, don't access the relationship ID via property
relationships
orfrom
{% 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
-
AuthorPosts
- You must be logged in to reply to this topic.