pppws Posted November 29, 2017 Share Posted November 29, 2017 hey there, i have the following structure for a repeater field: moments, 10x per page (unfortunatly a lot of pages, roughly 400) -- yearofmoment -- monthofmoment -- textofmoment i'm trying to find all repeater fields of certain year and sort them by month. e.g. get all repeater fields of year 1969, first repeater to be displayed: repeaters with monthofmoment = january. i already got this: <?php $langname = "es"; //temp: only get spanish profiles?> <?php $persons = $pages->find("template=persons, lang=$langname, moments.yearofmoment=1969") ?> <?php foreach ($persons as $p): ?> <?php foreach ($p->moments as $moments): ?> <?php if ($moments->yearofmoment == 1969): ?> <ul> <li><?= $p->givenname ?>,<?= $moments->month ?> <?= $moments->yearofmoment ?></li> </ul> <?php endif; ?> <?php endforeach; ?> <?php endforeach; ?> but somehow i can't figure out how to sort the repeater fields by month. the code above gives me this result: (julio should be on top, luis the last ) Link to comment Share on other sites More sharing options...
PWaddict Posted November 29, 2017 Share Posted November 29, 2017 You should add sort=your_month_field inside the selector. Link to comment Share on other sites More sharing options...
pppws Posted November 29, 2017 Author Share Posted November 29, 2017 (edited) this actually changes the order, but not in the way i need it. Edited November 29, 2017 by pppws added image. Link to comment Share on other sites More sharing options...
PWaddict Posted November 30, 2017 Share Posted November 30, 2017 If you want to display them in the same order as they are on backend just add sort=sort. Link to comment Share on other sites More sharing options...
pppws Posted November 30, 2017 Author Share Posted November 30, 2017 no, i want all of the repeaters sorted by month. not only their parent pages. the screenshot shows all pages wich include a repeater field with the year 1969. the names are the names of the pages. the second number is the month (1 = january, 4 = april and so on) but i don't need the pages to be sorted, but the repeater fields. so the list should be: julio, 1 selva, 4 gloria, 5 gloria, 5 gloria, 6 miguel, 6 sandra, 7 catalina, 8 luis, 10 hilda, 11 Link to comment Share on other sites More sharing options...
PWaddict Posted November 30, 2017 Share Posted November 30, 2017 Try to replace this: <?php foreach ($p->moments as $moments): ?> with this: <?php foreach ($p->moments->sort('month') as $moments): ?> Link to comment Share on other sites More sharing options...
Jonathan Lahijani Posted December 6, 2017 Share Posted December 6, 2017 Building on what PWaddict said, you could optimize the code just a little bit more, like this: <?php foreach ($p->moments->find('yearofmoment=1969,sort=month') as $moments): ?> You can then remove the conditional you have: <?php if ($moments->yearofmoment == 1969): ?> ... <?php endif; ?> 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