combicart Posted September 24 Share Posted September 24 Hello, I'm currently building an events website where one event can be in different locations. Each location can have it's own date. I therefore have added a repeater field called `event_locations` to an event where we can add more information about the location. The `event_locations` repeater contains the following fields: location (page reference) event_date (datetime field) event_price (text field) event_link (url field) On the event detail page I would like to show the different locations and sort them by date and city. Events in the past can be removed from the page. I normally check the date with `event_date>=today` which works whenever I loop through all pages and filter by template. However in this case I would like to filter through the repeater field which doesn't give the same results for some reason. This works (but displays all future event_locations): $pages->find('event_date>=today, sort=event_date, sort=location.location_city') This doesn't work (this give no results at all): $page->event_locations->find('event_date>=today, sort=event_date, sort=location.location_city') Can't the event_date be used in this case? Or is there a different way to get only events in the future for this specific event? Link to comment Share on other sites More sharing options...
da² Posted September 25 Share Posted September 25 Hi, maybe you can find help in this post: 1 Link to comment Share on other sites More sharing options...
combicart Posted September 26 Author Share Posted September 26 Thanks @da², I tried to solve it with an additional foreach loop but unfortunately that didn't work. Link to comment Share on other sites More sharing options...
da² Posted September 26 Share Posted September 26 Did you try this kind of selector? There's no loop, you directly get the repeater item. The part with "owner" is not mandatory, it depends if you want to do the search on a specific page or not. Link to comment Share on other sites More sharing options...
Jan Romero Posted September 26 Share Posted September 26 The difference between the two snippets you posted is that $pages->find() will make a database query and $page->event_locations->find() filters the repeater items already in memory (a PageArray). Confusingly, there are some features that are only available in one or the other. My guess is probably the “today” condition doesn’t work with in-memory selectors, because it doesn’t know you’re comparing dates at that point. So under the hood it’ll be something like 1726956531 >= 'today' (or maybe '09/22/2024 00:08' >= 'today' due to output formatting, I’m not sure). As @da² suggested, try this: $pages->find('template=repeater_event_locations, event_date>=today, include=all, event_locations.owner.id=' . $page->id . ', sort=event_date, sort=location.location_city') That should get all repeater items from the database which belong to $page. If you want to use $page->event_locations instead, I would suggest just foreaching them and skipping the ones you don’t want. You’re going to foreach them anyway, so you might as well do filtering and output in a single loop. But the other option should be more performant, because you’re never loading the ones you don’t need. 1 Link to comment Share on other sites More sharing options...
combicart Posted September 26 Author Share Posted September 26 @Jan Romero and @da², thanks for your help! I just tried it again with the selector from Jan and it gives the correct results. I didn't correctly understand the query from the original post for my situation but this helped a lot. Thanks! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now