Rob Posted July 18, 2012 Share Posted July 18, 2012 I have a repeater field where one of the constituent fields is a checkbox for whether the repeater item is "live" or not. What I want to do is fetch only those items from the repeater field where the "live" value is checked. Is this possible? Thanks. Link to comment Share on other sites More sharing options...
Soma Posted July 18, 2012 Share Posted July 18, 2012 I think it's easy if you see the repeaters as pages array Out of my head this can be done like this: $elements = $page->repeater->find("checkboxfield=1"); 1 Link to comment Share on other sites More sharing options...
slkwrm Posted July 18, 2012 Share Posted July 18, 2012 Yeah, Soma's right! You can do it this way: foreach ($page->myrepeater as $item) { if ($item->visible) { echo "<p>$item->title</p>"; //or do something else... } } or this: foreach ($page->myrepeater->find('visible=1') as $item) { echo "<p>$item->title</p>"; //or do something else... } 1 Link to comment Share on other sites More sharing options...
Rob Posted July 23, 2012 Author Share Posted July 23, 2012 Thanks chaps! I had tried that and thought it wasn't working, but in fact it was. What was happening was that I had pulled an entire page of data, then was trying to "overwrite" one part of it with the filtered version of itself. Trying to overwrite an object with an array = bad news! Link to comment Share on other sites More sharing options...
apeisa Posted December 3, 2012 Share Posted December 3, 2012 I can't seem to get repeater selectors work correctly with date fields. I have a repeater with four fields: photo (single image) bannerlink (page field) startdate (date) enddate (date) What I want to achieve is getting one random repeater which has startdate < time() < enddate. So it should have startdate which is before this very moment and enddate that is after this moment. Results I am getting are strange: // Get the current timestamp $time = time(); // I put my repeater pages into variable $banners = $page->shop_banners; // This is where things start to go strange $less_banners = $banners->find("enddate>0, enddate>$time"); foreach($less_banners as $p) { echo "START: " . $p->startdate . " < NOW: " . date("j.m.Y H:s", $time) . " < END: " . $p->enddate . "<br>"; } /* I have total 6 items, where 4 doesn't have anything on enddate, One has enddate before this moment and another has enddate after this moment. With that loop I get rows like: START: 7.8.2012 02:51 < NOW: 3.12.2012 14:42 < END: 4.12.2012 17:48 START: 2.12.2012 00:00 < NOW: 3.12.2012 14:42 < END: 2.12.2012 23:00 // THIS LINE SHOULD NOT BE HERE? */ // Then if I put it other way around: $less_banners = $banners->find("enddate>0, enddate<$time"); foreach($less_banners as $p) { echo "START: " . $p->startdate . " < NOW: " . date("j.m.Y H:s", $time) . " < END: " . $p->enddate . "<br>"; } /* I get zero results */ Show me where I am doing it wrong (I still have a bad gut feeling about doing something very silly here). I have tested this on pretty recent stable version and also latest dev version. I do similar stuff in many places (with events-item template etc), so I do know it should work - but for some reason I don't can get it working with repeaters. 1 Link to comment Share on other sites More sharing options...
DaveP Posted December 3, 2012 Share Posted December 3, 2012 It couldn't be a dd/mm/yy versus mm/dd/yy problem, could it? 1 Link to comment Share on other sites More sharing options...
apeisa Posted December 3, 2012 Share Posted December 3, 2012 Nope, it compares timestamps. Link to comment Share on other sites More sharing options...
ryan Posted December 3, 2012 Share Posted December 3, 2012 Antti, it looks like this is a result of output formatting being on, so it's doing a string comparison rather than a time comparison. This is not intended and not a detail people should not have to account for, so I'd consider it a bug. Thanks for tracking it down. The bug is only for in-memory finds on date fields, not database finds, as it's working how it should there already. I've put a fix in the latest commit to the dev branch of you want to try it out. It shows two files updated, but the only one that matters here is /wire/core/Array.php https://github.com/ryancramerdesign/ProcessWire/commit/393e420fc8ab60670dc4c874dd8436789be2897c 1 Link to comment Share on other sites More sharing options...
apeisa Posted December 3, 2012 Share Posted December 3, 2012 Thanks Ryan for superfast reply & fix, I'll test this tomorrow. 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