Jump to content

Filtering a Repeater Field on Output


SoccerGuy3
 Share

Recommended Posts

Is it possible to filter the output of a Repeater Field? Been playing around with different Repeater Fields on two different sites today. On one site I would like to output three entries at random from a bank of like 15 entries. On the other I would like to output only those events that have not happened yet (based on a date field in the repeater).

Currently using this code for the first example:

foreach($page->testimonials as $testi) {
    echo "<li>";
    echo "<h3>{$testi->testi_name}</h3>";
    echo $testi->testi_body;
    echo "</li>";
}

Link to comment
Share on other sites

Create two selectors and apply them as needed, like this (untested):

if(...) {
    $selector = 'limit=3, sort=random';
} else {
    $selector = 'date_field < today';
}

foreach($page->testimonials->find($selector) as $testi) {
...
}
Link to comment
Share on other sites

Beautiful! Worked perfect right out of the box!!

Thanks!

Create two selectors and apply them as needed, like this (untested):

if(...) {
    $selector = 'limit=3, sort=random';
} else {
    $selector = 'date_field < today';
}

foreach($page->testimonials->find($selector) as $testi) {
...
}
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...