SoccerGuy3 Posted July 16, 2015 Posted July 16, 2015 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>"; }
tpr Posted July 20, 2015 Posted July 20, 2015 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) { ... }
SoccerGuy3 Posted July 20, 2015 Author Posted July 20, 2015 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) { ... }
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