Home › Toolset Professional Support › [Resolved] View of upcoming events, but w/ dates & distance from 2 related child post types
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Hong_Kong (GMT+08:00)
Related documentation:
This topic contains 19 replies, has 4 voices.
Last updated by johnnyH-3 6 years, 1 month ago.
Assisted by: Luo Yang.
I have three post types: EVENTS, COURSES and RACES. EVENTS is related to the other two by one-to-many relationship. COURSES is also related to RACES with one-to-many.
Now I want to list upcoming races, but with the distances (from COURSES) from all the races of that event that occurs on the same day (or actually, all upcoming races of an event with start dates within 3 days of each other).
That is, each item in the list should display the event name, start date (as well as end date if different) of all upcoming races of the event that are within 3 days, and all the distances of the races of that event.
That is, I want to display the following fields:
- wpv-post-title from EVENTS
- event_location and event_county from EVENTS
- race_startdate from RACES
- courses_distance from COURSES for each of the races of the event
How can I achieve this? The page I'm working with is /upcoming-events/ and the main view is "View för kommande tävlingar".
Hello. Thank you for contacting the Toolset support.
Well - I need more information on your requirement.
You said:
That is, each item in the list should display the event name, start date (as well as end date if different) of all upcoming races of the event that are within 3 days, and all the distances of the races of that event.
=> do you mean that we should list all events greater than or equal to today's date and then search for races post that are within three days from today's days? or you mean you want to display both event and reces posts that fall within three days from now?
Ok. So EVENTS (Evenemang) has no date field. That post type contains the general info about an event, that may recur every year.
The RACES (Tävlingar) post type is an instance of an event, that occurs on a specific date. So that post type contains the field race_startdate (Startdatum), as well as race_enddate (Slutdatum). Each race has one course. But an event can have many courses.
The COURSES (Banor) post type contains all courses that an event can use. Each race that occurs on a specific date is using one of the courses of the event (EVENTS is parent to both COURSES and RACES). The field I want to use from COURSES is course_distance (Distans).
See attached data model.
Ok - I understand what you said but cold you please give me specific requirement.
Do you want to display Race posts whose Startdatum(startdate) is within 3 days from now - correct? do we need to compare end-date as well?
Well, the basic requirement is to display all races with the same start date as one item in the list. Similar to hidden link
One item in the list should contain:
- Event name from the Events (Evenemang) post type
- Location & county from the Events (Evenemang) post type)
- Start date from the Races (Tävlingar) post type
- Distance from the Courses (Banor) post type, for each race of the event, that has the same start date.
If possible, I would in the next step like to include all races with start dates (Startdatum) within 3 days of each other in the same list item.
Example:
1. A single post in "Evenemang" post type:
1a. Kullamannen
2. Posts in "Tävlingar" post type , connected to the above evenemang via the one-to-many relationship "Evenemangets tävlingar":
2a. Kullamannen 100 miles 2018, with the start date 3.11.2018 (also connected to the post in the "Banor" post type, with the title Kullamannen 100 miles, via the relationship "Tävlingar som använder banan").
2b. Kullamannen Dubbeldöden 2018, with the start date 4.11.2018 (also connected to the posts in the Banor post type with the title "Kullamannen Dubbeldöden", via the relationship "Tävlingar som använder banan").
3. Posts in "Banor" post type, that are connected to the evenemang in #1 (via the relationship "Evenemangets banor", and to the tävlingar (races) in #2 (via the relationship "Tävlingar som använder banan"):
3a. Kullamannen 100 miles (that includes the fields Distans (course_distance) & Enhet (course_unit) with the values "100" & "miles")
3b. Kullamannen Dubbeldöden 2018 (that includes the fields Distans (course_distance) & Enhet (course_unit) with the values "44" & "km".
The above two races belong to the same Event, but have different start dates and different courses (from which Distance/course_distance is derived). In the basic scenario each of the above races could be a list item.
But in the ideal scenario both of the above races would be a combined list item with the following values:
- Event title: Kullamannen
- Date: 3-4 Nov 2018
- Distances: 44 km, 100 miles
But in the ideal scenario both of the above races would be a combined list item with the following values:
- Event title: Kullamannen
- Date: 3-4 Nov 2018
- Distances: 44 km, 100 miles
==> Well - there is no way to combine the dates, as race and distance posts are in loop and in relationship. We can list it as given under.
Ok - so I've add all field which you want to display:
=> hidden link
Now, only thing remaining is - exactly what dates you want to include, as I can see there is no test Race posts setup so that I can setup date filters for you.
Could you please setup one standard test case using which we can test all requirement date etc..etc..
Great, thanks!
I have now created 4 races connected to the event "Tjörnarparen", each with their own course. As you can see on hidden link, they show up as individual list items. But I would like to have them all in one list item, as they share the same event title and start date, but list the different distances as a sub-view within the list item.
Same goes for the event Kullamannen, but those races have two different start dates. Possibly to have them both in the same list item, with dates showing as 2-3 November?
Well - to group posts by title, I've added following code at:
=> hidden link
add_shortcode('group-title', 'func_group_by_display_title'); function func_group_by_display_title($atts, $content = '') { static $title = null; $condition = $atts['condition']; $value = $atts['value']; switch ($condition) { case 'title': if ($$condition != $value) { $$condition = $value; return $content; } break; } return ''; }
Then, within your view, we are displaying the title as given under:
[group-title condition="title" value="[wpv-post-title item='@evenemang-tavling.parent']"] [wpv-post-title item='@evenemang-tavling.parent'] [/group-title]
As you can see now, Race are grouped by parent title:
=> hidden link
Same goes for the event Kullamannen, but those races have two different start dates. Possibly to have them both in the same list item, with dates showing as 2-3 November?
==> as I try to explain you in my previous reply that its not possible because we are looping through the records. However, anything is possible but that needs custom code which is unfortunately beyond the scope of our support policy. You may try to write the custom shortcode that fulfills your requirement.
Thanks! I was working with the same view, adding some other HTML. So I think the output now is not the expected: hidden link
Currently I can see the event title on the first occasion, but there are still a list item for each race of that event, even though the event title doesn't display for others than the first.
Sorry for the mess-up...
Please check now: hidden link
Fortunately - I didn't close your site otherwise it will be total rework for me. Please kindly be patient from next time 🙂
Ok. There is still one date for each race, though, as well as location and county for each race, rather than only once for each event.
I was trying to wrap all that code within the [group-title] short code, but then it outputs none of that data.
I wish I better understood the custom PHP code to understand why that is so. That is, I would like the date, location and county to only show once for the event, but all of the distances.
Thanks for your patience! I'll not work with the view for now. 🙂
Well - I tried to help as much as I can but now the solution leads to the custom programming. As a supporter even I need to work within the support policy, I hope this is understandable.
I wish I better understood the custom PHP code to understand why that is so. That is, I would like the date, location and county to only show once for the event, but all of the distances.
==> There is no native way to achieve this until you write custom code as per your need.
I show you a way how you can do this but this indeed needs custom programming, even you can see that as well. If you need custom programming for your project, please feel free to contact our certified partners:
=> https://toolset.com/contractors/
If you have any other query that falls within our support boundary, please feel free to create a new ticket. We would love to help you with your query.
Yeah, I understand you can not give support for any custom coding. I did get most of it to work by adding a function also to treat date and location similarly, and then wrapping the entire code in the [group-title] shortcode.
But within the [group-title] shortcode I am also trying to display the distances. But it seems as if it doesn't work to display items from parent posts within that shortcode? It works to display any field from the "Tävlingar" post type, but not from its parents within the [group-title] shortcode.
Is there an easy solution to this or something that requires a significant amount of custom coding?
Still working with the view "View för kommande tävlingar".
Well - so finish your editings and let me know where exactly you want to display what.
I will take a look first thing on next Monday - have a great weekend.
I have set the next reply to private which means only you and I have access to it.