Soma Posted September 23, 2013 Share Posted September 23, 2013 I can't get the pages that have repeater.count=0 No results: $pa = $pages->find("template=basic-page,myrepeater.count=0"); doesn't give me the pages where there's no repeater element created yet. Works: $pa = $pages->find("template=basic-page,myrepeater.count>0"); this works correct $pa = $pages->find("template=basic-page,myrepeater.count=2"); this also. I have Language Support installed, in case that matter at all. I have tested in different installs and I can't get it to work, but thought I was able to do this count=0 on repeaters the other day. Anybody able to reproduce this? Link to comment Share on other sites More sharing options...
Soma Posted September 23, 2013 Author Share Posted September 23, 2013 Testing further: Deinstalled Language Support to rule that out. Now I found out: The repeater.count=0 only works for pages that are once saved after the repeater is added to the template. So to say it different: For pages that are not yet saved, once after the repeater was added to the template, it doesn't find them. 1 Link to comment Share on other sites More sharing options...
nik Posted September 23, 2013 Share Posted September 23, 2013 Yep, seems to work like you described Soma here as well. This is what I'm seeing: when a repeater field "xx" is added to a template "yy", no data is written into field_xx for pages with template "yy". And because selector "zz.count" relies on column "count" in field_xx, the selector doesn't work. But when such a page is saved the next time, a row with proper "count" value is written into field_xx and the selector works as expected. I guess those rows should be written for all pre-existing pages of the template when a repeater is added. Either that or some more SQL to cover the non-existing rows when <repeater>.count is used. 1 Link to comment Share on other sites More sharing options...
Soma Posted September 23, 2013 Author Share Posted September 23, 2013 Thanks Nik fr confirming. Another thing: (was my problem only) Further more I noticed something else again maybe related. I created repeater items via API for those pages. Now I can't access them with $page->repeater->first() $page->repeater->first() // doesn't return the first repeater although it's there. Once I go to edit the page and change a value on that repeater item and save, it works. Ok this is my fault sorry. I was using the Shop module and the integer value is required to show the add to cart and I missed that it requires the price to show. Link to comment Share on other sites More sharing options...
ryan Posted September 28, 2013 Share Posted September 28, 2013 Thanks for the report. I was able to duplicate it too. Can you try replacing your /wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeRepeater.module with the attached file and let me know if that fixes it for you too? FieldtypeRepeater.module To fix it, I replaced this line get getMatchQuery(): $query->where("($table.count{$operator}$value)"); with this: if(($operator == '=' && $value == 0) || (in_array($operator, array('<', '<=')) && $value > -1) || ($operator == '!=' && $value)) { $templateIDs = array(); foreach($field->getTemplates() as $template) $templateIDs[] = (int) $template->id; if(count($templateIDs)) { $templateIDs = implode(',', $templateIDs); $sql = "($table.count{$operator}$value OR " . "($table.count IS NULL AND pages.templates_id IN($templateIDs)))"; $query->where($sql); } else { $query->where("1>2"); // forced non-match } } else { $query->where("($table.count{$operator}$value)"); } Hopefully I got the logic right on this one, as it's a little different need than count() situations for other Fieldtypes. Most fieldtypes don't keep track of their own counts and PW relies on the quantity of rows present in the table instead. Link to comment Share on other sites More sharing options...
ryan Posted September 28, 2013 Share Posted September 28, 2013 Edit: just updated the post to account for the "!=" operator, and also updated the FieldtypeRepeater.module file. Link to comment Share on other sites More sharing options...
DaveP Posted April 15, 2014 Share Posted April 15, 2014 I see that Ryan's fix above has been downloaded 19 times before I just did, but no-one has commented on its efficacy. It doesn't seem to have worked for me, as I still have the problem Soma originally reported, except that saving the pages makes no difference. Does anyone have any comments or updates? Link to comment Share on other sites More sharing options...
joe_g Posted September 30, 2014 Share Posted September 30, 2014 I ran into this issue again, and ryans file works, but only for new entries (after fix is applied). I've got a project with lot of repeater data that I can't enter all over again. Is there a way to loop through all repeaters and publish them for all languages? Link to comment Share on other sites More sharing options...
joe_g Posted October 1, 2014 Share Posted October 1, 2014 I tried looping through the repeater values and publishing them for all languages, but no luck so far: (site is 2.4) $pages->setOutputFormatting(false); $pps = $pages->find('has_parent=/processwire/repeaters/for-field-116/'); foreach($pps as $p) { foreach($languages as $lang) { if($lang->isDefault()) continue; $p->set("status$lang", 1); echo "set status$lang" . $p->title . ' <br>'; $p->save(); } } die; 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