Jump to content

Selecting and sorting repeater-field-entries from multiple pages


cabrooney
 Share

Recommended Posts

Is there a simple solution to generate (find) and sort an array of repeater field entries, that come from multiple pages?

In my case the setup is like this:
- I have pages for "theater plays" (storing title, text, artists etc.).
- Each of these pages has a repeater field in it for the dates that the play is performed (storing datetime, location, tickets, prices etc.) 

Now i need to generate an overview showing all the events (Titel and date) that will take place in december.

 

What i managed to do so far is to search for a timespan, but only in one repeaterfield on one page (and the results are not sorted):

$zeit_start = strtotime("2021-12-01 00:00:00");
$zeit_end = strtotime("2021-12-31 00:00:00");    
$terminliste=$page_play->termin_repeater->find("termin_datum>=$zeit_start , termin_datum<=$zeit_end ");

foreach($terminliste as $termin){
   // echo $termin->title;
}

So how can i use "find()" to scan all the repeater field entries of all the pages, and how can i then uns "sort()" to bring them in the right order?

 

Link to comment
Share on other sites

Hello @cabrooney,

repeater items have their own system template:

You should be able to find them and sort them like this:

$zeit_start = strtotime("2021-12-01 00:00:00");
$zeit_end = strtotime("2021-12-31 00:00:00");    

$terminliste = $pages->find("template=repeater_termin_repeater, termin_datum>=$zeit_start , termin_datum<=$zeit_end, sort=termin_datum");

Maybe you have to add "include=all" too, if the selector doesn't find anything while you are logged-out. I am not sure if that is necessary.

Regards, Andreas

  • Like 1
Link to comment
Share on other sites

Thank you very much for your help. it worked perfectly! Here is my final code:

$zeit_a = strtotime($jahr."-12-01 00:00:00");
$zeit_b = strtotime($jahr."-12-31 23:59:59");                                
                                
$terminliste=$pages->find("template=repeater_termin_repeater, include=all, sort=termin_datum, termin_datum>=$zeit_a, termin_datum<=$zeit_b");

One other thing i had to figure out after that was the use of ->getForPage() to get access to the "origin" page. 

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...