Jump to content

Repeating Fields count() but getting differing results between frontend and API


Recommended Posts

Hi all,

Just wondering if anyone else has encountered this issue.

During some work recently I have noticed that it seems like when you use count() on a repeating field to determine if theres any content to output, it works fine on a template but behind the scenes as part of a module it doesn't return the same results on the same data set.

For instance.


On the frontend template this outputs as you would imagine:


Doing a count on that same field, from within a module I get count() returning as 2, which makes sense as both are enabled.

However I noticed that, if I then disable one of the repeating items, ala:


This is reflected in the frontend as you would imagine, like so:


However within the module logic, the value of count() on the same data set will still return as 2

The fact that I can't rely on the count within the module being correct is having major knock on effects as I have no idea whether to trust any information brought back about that repeating field.

Does anyone know a way to get a correct number from a repeating_field->count or count(repeating_field) from the API, that actually takes into account the enable/disabled status of the elements within it?

I have tried using various methods which are fine on a page template but just seem unreliable in my modules context, for some clarity, this is how I am pulling out the same field via the module:

$overrides = $this->pages->findOne("template=plot, parent.id="666", title=plot 101");

then the following to check if there any content within the repeater


For the record the following also appears to be giving the same as above


So presumably this is a bug or COUNT() works diffferently between use in templates and usage with the API?

If its working as intended, can anyone point me towards some documentation that explains the differences?

Any thoughts would be much appreciated?



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

  • Create New...