Jump to content

Recommended Posts

Posted

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 )

Screenshot%202017-11-29%2018.24.27.png?d

 

Posted (edited)

this actually changes the order, but not in the way i need it. 

 

Screenshot%202017-11-30%2000.40.17.png?d

 

 

Edited by pppws
added image.
Posted

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

 

 

Posted

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; ?>

 

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
  • Recently Browsing   0 members

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