Jump to content

Count matching results within a repeater


a-ok
 Share

Recommended Posts

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

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

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

Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

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