SoccerGuy3 Posted July 16, 2015 Share 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>"; } Link to comment Share on other sites More sharing options...
SoccerGuy3 Posted July 20, 2015 Author Share Posted July 20, 2015 bump Link to comment Share on other sites More sharing options...
tpr Posted July 20, 2015 Share 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) { ... } Link to comment Share on other sites More sharing options...
SoccerGuy3 Posted July 20, 2015 Author Share 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) { ... } 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