a-ok Posted July 22, 2016 Share Posted July 22, 2016 I have a repeater set up 'article_overview_flexible_layout' and within each repeater is an options field 'article_overview_flexible_layout_type'. Before I loop through each repeater I want to get the total number of 'article_overview_flexible_layout_type' that equal the id '4'. I thought this (below) might've worked, but the main thing is that I don't want to loop through (foreach); is there a way to get the count as a single query? Thanks. count($page->article_overview_flexible_layout.article_overview_flexible_layout_type.id === 4) Link to comment Share on other sites More sharing options...
Soma Posted July 22, 2016 Share Posted July 22, 2016 What you are looking for is rather something like find selector but with count $count = $page->article_overview_flexible_layout->count("article_overview_flexible_layout_type.id=4"); Link to comment Share on other sites More sharing options...
a-ok Posted July 22, 2016 Author Share Posted July 22, 2016 3 minutes ago, Soma said: What you are looking for is rather something like find selector but with count $count = $page->article_overview_flexible_layout->count("article_overview_flexible_layout_type.id=4"); Thanks (again!) Soma. I did try this but it was returning all the repeater rows (6) rather than (3) which in this case is the number of repeater rows that has article_overview_flexible_layout_type set to 4. Link to comment Share on other sites More sharing options...
Soma Posted July 22, 2016 Share Posted July 22, 2016 Then maybe the options field is not .id= but something different. I would try .value= or .data= Link to comment Share on other sites More sharing options...
a-ok Posted July 22, 2016 Author Share Posted July 22, 2016 8 minutes ago, Soma said: Then maybe the options field is not .id= but something different. I would try .value= or .data= It doesn't seem like ->count() accepts a selector as when I put $page->article_overview_flexible_layout->count("ffvsdsdf"); it still returns 6. Link to comment Share on other sites More sharing options...
Soma Posted July 22, 2016 Share Posted July 22, 2016 That could be that in memory PageArray filtering doesn't work with count(). Just use a normal find(selector)->count ... Link to comment Share on other sites More sharing options...
a-ok Posted July 22, 2016 Author Share Posted July 22, 2016 I worked it out as the following... $repeater = $page->get('article_overview_flexible_layout'); $count = $repeater->find('article_overview_flexible_layout_type=4')->count(); Link to comment Share on other sites More sharing options...
tpr Posted July 22, 2016 Share Posted July 22, 2016 Perhaps you could get it in one go using parent=... in your selector. 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