Jump to content

Recommended Posts

Posted

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)

 

Posted

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");
Posted
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.

Screen Shot 2016-07-22 at 17.04.57.png

Posted

Then maybe the options field is not .id= but something different. I would try .value= or .data=

Posted
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.

Posted

That could be that in memory PageArray filtering doesn't work with count(). Just use a normal find(selector)->count ...

Posted

I worked it out as the following...

$repeater = $page->get('article_overview_flexible_layout'); 
$count = $repeater->find('article_overview_flexible_layout_type=4')->count();

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...