Team > Topic > Event in a View
- This topic has 6 replies, 2 voices, and was last updated 2 months, 3 weeks ago by
swest.
-
AuthorPosts
-
February 14, 2025 at 4:39 AM #47657
swest
ParticipantWe are building a way to display the topics our team members present at speaking events.
I have Custom Post Types for Team Members (team), Topics (topic), and Events (events)
with the following Relationships:- Team to Topic (team-to-topic)
- Topic to Event (topic-to-event
One view of the data will be to display the Topics of an individual Team Member on the Single Team page.
I have the view working except for one line where I want to display the related topic_datetime followed by the related event.name.
The view displays everything correctly except for the event.name. Can you tell me what I am doing wrong?View: team-member-topic-view
https://pastebin.com/C57JiN93The problem is in the second part of this div: <div class="topic-date-and-event-name">
I've tried to annotate a screenshot of this view's output and where the problem lies. I can give you access to the staging site if that would help.
https://share.cleanshot.com/s3gJjfz0I did see in this support post a solution for traversing multiple related CPTs: https://support.metabox.io/topic/traversing-multiple-related-cpts/
I updated the view code for my custom post type configuration, but it returned fatal query normalizer errors.
https://share.cleanshot.com/Hr6wjQQpSingle Team Member Topics view:
https://pastebin.com/f3WD9DXNAny help you can give will be appreciated.
February 14, 2025 at 10:25 PM #47663Peter
ModeratorHello,
Can you please also share the settings of 2 relationships?
- Team to Topic (team-to-topic)
- Topic to Event (topic-to-event)I check this View code https://pastebin.com/f3WD9DXN
but don't see any issue when outputtingtopic
andevent
posts.February 14, 2025 at 10:57 PM #47664swest
ParticipantTopic to Team Relationship
https://pastebin.com/yg9iBdYwTopic to Event Relationship
https://pastebin.com/5wWAL2WvI check this View code https://pastebin.com/f3WD9DXN
but don't see any issue when outputting topic and event posts.Can I give you access to the staging site where I am seeing the fatal errors?
February 14, 2025 at 11:28 PM #47666Peter
ModeratorHello,
The relationship ID in the query args is wrong. This is the relationship settings:
function your_prefix_function_name() { MB_Relationships_API::register( [ 'id' => 'event-to-topic',
this is the query args
{% set topic_args = { relationship: { id: 'relationship-team-to-topic', from: post.ID }, nopaging: true, post_type: 'topic' } %}
it should be
event-to-topic
, notrelationship-team-to-topic
. Where do you get this IDrelationship-team-to-topic
?Here is the updated query args
{% set topic_args = { relationship: { id: 'topic-to-team', to: post.ID }, nopaging: true, post_type: 'topic' } %} {% set event_args = { relationship: { id: 'event-to-topic', to: topic.ID }, nopaging: true, post_type: 'event' } %}
Let me know if it helps.
February 15, 2025 at 3:01 AM #47667swest
ParticipantThank you, that helped.
In the View, how do I set an orderby?
I tried:
{% set topic_args = { relationship: { id: 'relationship-team-to-topic', from: post.ID }, nopaging: true, post_type: 'topic', orderby: '{ post.topic_datetime | date( 'Y-m-d H:i' ) }', order: 'ASC' } %}
but it resulted in fatal errors.
February 15, 2025 at 8:36 PM #47668Peter
ModeratorHello,
If you use the variable, you should remove the curly brackets and single quote from the query arg:
{% set topic_args = { relationship: { id: 'relationship-team-to-topic', from: post.ID }, nopaging: true, post_type: 'topic', orderby: post.topic_datetime | date( 'Y-m-d H:i' ), order: 'ASC' } %}
February 16, 2025 at 1:34 AM #47669swest
ParticipantThat worked great.
Thank you very much for your help. -
AuthorPosts
- You must be logged in to reply to this topic.