Event Single with data from Event and related Topics with related Team Member

Support MB Views Event Single with data from Event and related Topics with related Team Member

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #47693
    swestswest
    Participant

    I had a recent community support ticket at:
    https://support.metabox.io/topic/team-topic-event-in-a-view/

    I have Custom Post Types for Events (events), Topics (topic), and Team Members (team)
    with the following Relationships:

    Team to Topic (team-to-topic)
    Topic to Event (topic-to-event

    That was for the Single Team member page.

    Now I am on to the Single Event page, where I need Event data, a loop for Topic data, and Related Team Member data.

    I have a view set up and am pulling the data for the Event and the related Topics, but I am having difficulty getting the related Team Member data. The data I need from the Team member is the featured image and the team_member_name.

    Pastebin is currently undergoing maintenance, so I used a GitHub Gist:
    https://gist.github.com/swest/56de57093c8ca1af90635e23200b81cb

    The Gist contains the post type definitions, the relationship definitions, and the single-event_view.twig file.

    https://share.cleanshot.com/VhGY1fPl

    Any help you can give will be appreciated.

    #47694
    swestswest
    Participant

    Single Event page.
    https://share.cleanshot.com/VhGY1fPl

    #47702
    PeterPeter
    Moderator

    Hello,

    Please notice the side connection in the relationship: FROM or TO

    'id'          => 'event-to-topic'
    'id'          => 'topic-to-team',

    then you can correct the directional from or to when using the query to get the relation post.

    Following the previous topic, you can use two query args

    {% set topic_args = { relationship: { id: 'event-to-topic', from: post.ID }, nopaging: true, post_type: 'topic' } %}
    
    {% set team_args = { relationship: { id: 'topic-to-team', from: topic.ID }, nopaging: true, post_type: 'team' } %}

    I hope that makes sense.

    #47708
    swestswest
    Participant

    Where would I add those query args in my single-event_view.twig?
    https://gist.github.com/swest/56de57093c8ca1af90635e23200b81cb#file-single-event_view-twig

    Does it replace these?
    Line 10

    
    {% set relationship = attribute( relationships, 'event-to-topic' ) %}
            {% for post in relationship.to %}
    

    AND
    Line 21

    
    {% set relationship = attribute( relationships, 'topic-to-team' ) %}
                {% for post in relationship.to %}   
    
    #47709
    swestswest
    Participant

    I think I got it. Thanks for the nudge in the right direction.

    Here's my final view:

    https://pastebin.com/apfVGCRZ

    For another view (All Events) can I just loop the entire Event Single view?

    #47713
    PeterPeter
    Moderator

    Hello,

    Yes, for the archive page (all Event posts), you can create a separate query and use the loop to show Event posts. Please follow the documentation to include other views in a view template
    https://docs.metabox.io/extensions/mb-views/#include-other-views

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