I am wondering if this is possible... I list Shows (Posts) and Venues (CPT) on my site. Each show has a list of all the venues the show will be appearing at and the dates:
eg The Lion King is on at Wimbledon from the 1st - 10th Sept. This show will have several other venues listed with their dates.
Is there a way to plot all these intermediary dates on a calendar so that I can see at any one time what shows are playing on that date and at which venues? Or is there a way to display this as a View?
This would be for my own reference so I don't care how it looks, I just want to be able to click on or search a date and see what shows are playing on said date and where.
It sounds like you have a many-to-many relationship between Shows and Venues, where there is an intermediate post type used to store the dates.
You can create a View to query the intermediate posts, and that can be a search View including a filter for the dates.
In the output section of the View, although the posts being looped over are the intermediate posts you can specify the parent Show and Venue posts when outputting fields, so you output something like post title (of Show) @ post title (of Venue) on dates.
(If you are using the block editor, using something like a standard Heading block and Toolset's inline fields would be a good option, otherwise with the legacy editor you'd be inserting shortcodes as usual.)
There isn't a way to output these on a calendar, but you can output them as a list.
Not sure what to put in Ordering or Query Filter... and in the Loop Wizard I don't know what fields to set up in the loop.. whatever I have tried nothing displays.
Would you mind taking a look? I have NO idea what I am doing here. Complicated Views are beyond me. Would really appreciate the help!
Hello there! If you don't mind, I'll continue with you on this ticket.
I don't think you will need to add anything to the Query Filter. You can set the order to the date field(start or end) in the intermediary post fields. And to display the dates, just click on the views' button and choose the custom field that holds the date(start or end).
Sure, I can take a look at the view and see what we can do. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
As explained above I want to be able to search my CPT posts, so I have been able to successfully set up a View using what Nigel suggested:-
"You can create a View to query the intermediate posts, and that can be a search View including a filter for the dates."
This is the page it's on: hidden link
But my issue is that the search filters I have 'Booking From and Booking Until' are not working together. For example, if I select Booking From-Sept 1st - Booking Until-Sept 31st, I expect the results to show me all posts that fall between these dates but it is not working like this.
This is the Search and Pagination code in the view:
Can I log into your website and check this further? I want to activate the views debugging tool to inspect the underlying SQL queries for the view. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
First, you will need to activate the query filter of the view in the screen options. Check this screenshot hidden link
The query filters were not correct. Check this screenshot hidden link
So, I removed the filters in the "Search and Pagination" section, and their respective filters in the "Query Filter" section. And I recreated them again. When creating the filter, we need to check that the post's booking-from is greater or equal to url parameter(booking-from), and the booking-unil is lower or equal than the url paramter(booking-until). Check this screenshot hidden link
Please check this example, and let me know if something is not working as expected hidden link
The dates chosen are for the month of September, but if you scroll to the bottom of the page you linked to, you will see three posts outside of that date range - one in Feb, and two in June - do you know what's happening here?
I noticed you put a Submit button instead of just Ajax - is this a better way to do it?
Also, you said in one of the screenshots that the Booking Until search filter was bit odd, but the View still worked - what was odd here? Do you suggest something different?
The dates chosen are for the month of September, but if you scroll to the bottom of the page you linked to, you will see three posts outside of that date range - one in Feb, and two in June - do you know what's happening here?
This is not an issue with the view. It is rather an issue with the dates on those intermediary posts. They have the booking from in 2022 and the booking until in 2021. Which makes the condition match(2022>=Sep 2021, and April2021<=Sep 2021).
Check these screenshots:
- hidden link
- hidden link
- hidden link
If you update the "Booking From" or the "Booking until" values of these posts, they won't appear on the search for the month of September 2021. Does it make sense?
I noticed you put a Submit button instead of just Ajax - is this a better way to do it?
Yes, I did, so I can reload the page and get the Views debugging popup. Please update the view again to make it work with AJAX.
the Booking Until search filter was bit odd, but the View still worked - what was odd here? Do you suggest something different?
I said it is odd because the second filter should be displayed in the same way as the first filter(except for lower-vs-greater, and the URL parameter of the field). As long as the search is working, I do not see any benefits from taking time to debug the display of that filter. Would you agree?
I wonder if the Booking Until Search filter is affecting the View because I have discovered if a date is selected which is between the dates shown the post will not appear.
For example, using a show with the following dates as an example: Wed 01 Sep – Sun 05 Sep 2021
If I do a search for all shows playing between the 2nd and 6th of September, I would expect this show to be included in the result.
If I select shows playing from the 1st to the 5th, it shows up, but if I select any combination of the following dates: 1st, 2nd, 3rd, 4th, 5th (other than 1 and 5) - it is not included in the results.
I am not sure to understand fully what do you mean. Taking posts from 1st to 5th September 2021, we get one post as shown on this screenshot hidden link
Do you mean that this should also appear when looking between 2nd and 6th, or 3rd and 7th, because the 5th(booking untill) is between both dates?
This means, that either the "Booking From" or "Booking Until" is between the selected dates?
Well, that will require custom coding. Because by default Views use an AND rule for custom fields conditions. You are looking to search for posts that have either the from "OR" until bookings dates between the searched interval, while views will by default search for posts that have both from "AND" until bookings dates between the searched interval. Does it make sense?