We are trying to set up a schedule page that will have multiple dates pulled from a custom date/time field called Match Date and Time. Within each date there will be multiple results from a Match content type. We've set up four test matches for building this schedule page. Two matches are May 9, 2023, two matches are May 10, 2023.
You can see our first effort at this page here:
hidden link
Currently, the date field is showing for ALL matches on the schedule page. We'd prefer to have this output show as follows:
Schedule
May 9, 2023
Team 1 vs. Team 2
Team 6 vs. Team 7
May 10, 2023
Team 3 vs. Team 4
Team 5 vs. Team 9
This way the dates will basically be headers that only display once and then all the Matches starting on that date will display below that date.
I'm not sure how to set up the date field in this way. Thanks in advance for any assistance you can provide.
Hello,
It is possible with some custom codes, see the same sandbox website:
Login URL: hidden link
1) In your theme file "functions.php", add lines 659~676
hidden link
line create a custom shortcode "heading":
add_shortcode('heading', 'my_heading');
function my_heading($atts, $content = '') {
static $year = null;
static $month = null;
$condition = $atts['condition'];;
$value = $atts['value'];;
switch ($condition) {
case 'year':
case 'month':
if ($$condition != $value) {
$$condition = $value;
return $content;
}
break;
}
return '';
}
2) Add a custom date field "Match date" to post type "Matches":
hidden link
3) Create a page "Schedule":
hidden link
display a view block:
- Query "Matches" posts
- Order the results by custom date field "Match date"
- In view's loop, display custom shortcode [heading] like this:
[heading condition="year" value="[types field='match-date' style='text' format='F j, Y'][/types]"]
<h4>[types field='match-date' style='text' format='F j, Y'][/types]</h4>
[/heading]
And display the match teams like this:
[wpv-post-link item="@team-a-matches.parent"] vs. [wpv-post-link item="@team-b-matches.parent"]</p>
See the result:
hidden link
Please check if it is what you want.
This worked perfectly, but I did change your approach to displaying the match teams to:
[types field='team-name' item='@team-1-match.parent'][/types] vs. [types field='team-name' item='@team-2-match.parent'][/types]<br>
I might not have had to do that, but it works so I left it like this. Let me know if that's a bad idea for any reason.
Thanks hugely!!!
Yes, you can customize it as what you want, it is just a demo for your reference.
My issue is resolved now. Thank you!