Create a view with information from three different related post types

Support MB Views Create a view with information from three different related post types

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #34154
    Catharina von HobeCatharina von Hobe
    Participant

    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.

    #34163
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please refer to this topic to traverse multiple related CPTs A > B > C
    https://support.metabox.io/topic/traversing-multiple-related-cpts/

    #34172
    Catharina von HobeCatharina von Hobe
    Participant

    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 ) %}

      {% 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 🙂

    #34176
    Long NguyenLong Nguyen
    Moderator

    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

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