Skip Navigation

[Resolved] Display all intermediary data on site in one View

This support ticket is created 3 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

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: Africa/Casablanca (GMT+01:00)

This topic contains 18 replies, has 3 voices.

Last updated by Jamal 3 years, 9 months ago.

Assisted by: Jamal.

Author
Posts
#2164521

Hi there,

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.

Many thanks.

#2165437

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

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.

#2165595

Hi Nigel,

That is correct, it is a many-to-many relationship.

I am trying to set up this view and not having much luck... I don't use blocks, I use the legacy Views.

Content Selection - Do I select Shows (Posts) or Posts Venues Intermediary Posts? When I select the latter I don't get the dates I get this:

Posts Venues: 11134 – 5098
Posts Venues: 11134 – 5120
Posts Venues: 11134 – 8297
Posts Venues: 11134 – 5134

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!

#2165735

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. **

#2172403

Hi Jamal,

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:

<div class="form-group"><label for="wpv-wpcf-booking-from"> [wpml-string context="wpv-views"]Booking From[/wpml-string]</label> - [wpv-control-postmeta field="wpcf-booking-from" url_param="wpv-wpcf-booking-from"]
<br>
<label for="wpv-wpcf-booking-until"> [wpml-string context="wpv-views"]Booking Until[/wpml-string]</label> - [wpv-control-postmeta field="wpcf-booking-until" url_param="wpv-wpcf-booking-until"]</div>

What do I need to add to this to make it work?

The Custom Search Settings: AJAX results update when visitors change any filter values

Thanks for your help!

#2173099

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. **

#2174795

Hi Jamal, just to let you know there are no queries in place as I just couldn't get them to work...

The intermediary date fields are as follows: wpv-wpcf-booking-from | wpv-wpcf-booking-until

#2174879

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

#2175039

Hi Jamal,

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?

Thanks so much

#2175143

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?

#2176009

Hi Jamal, thanks for the explanations.

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.

Any ideas?

#2178303

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?

#2178321

Yes, that's what I mean. 🙂 What do I need to do to the View to enable this?

#2178439

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?

For that you will need to use the wpv_filter_query
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
And inside of it change the meta_query relation from AND to OR:

$query_args['meta_query']['relation'] = 'OR';

It should be pretty simple. Let me know if you would need help with it.

#2181443

Hi Jamal, do I need to copy and paste this in the View or in Functions?

If in Functions, I would need it to relate to the View, so I assume I would need to use '$view_id ' but have no idea how to include it here.

I really appreciate your help with this. I can do HTML and CSS but I am out of my depth here. Thanks.