Event Single with data from Event and related Topics with related Team Member
- This topic has 5 replies, 2 voices, and was last updated 8 months, 2 weeks ago by
Peter.
-
AuthorPosts
-
February 20, 2025 at 5:28 AM #47693
swest
ParticipantI 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-eventThat 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/56de57093c8ca1af90635e23200b81cbThe 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.
February 20, 2025 at 5:29 AM #47694swest
ParticipantSingle Event page.
https://share.cleanshot.com/VhGY1fPlFebruary 20, 2025 at 9:00 PM #47702Peter
ModeratorHello,
Please notice the side connection in the relationship:
FROMorTO'id' => 'event-to-topic' 'id' => 'topic-to-team',then you can correct the directional
fromortowhen 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.
February 20, 2025 at 10:45 PM #47708swest
ParticipantWhere would I add those query args in my single-event_view.twig?
https://gist.github.com/swest/56de57093c8ca1af90635e23200b81cb#file-single-event_view-twigDoes 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 %}February 21, 2025 at 2:50 AM #47709swest
ParticipantI think I got it. Thanks for the nudge in the right direction.
Here's my final view:
For another view (All Events) can I just loop the entire Event Single view?
February 21, 2025 at 10:47 PM #47713Peter
ModeratorHello,
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 -
AuthorPosts
- You must be logged in to reply to this topic.