Jump to content

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


cosmicsafari
 Share

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.

image.thumb.png.7cbfb83aa84404d39efb1e8d7109375b.png

On the frontend template this outputs as you would imagine:

image.png.04a77a4905bffd53d41a68402892b6e1.png

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:

image.thumb.png.30e5a2d0be31112488ab530ca690aa68.png

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

image.png.400b429c5b8bec98f01b3788b5bd4397.png

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

error_log('COUNT:'.count($overrides->key_features));

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

error_log('COUNT:'.$overrides->key_features->count);

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
 Share

×
×
  • Create New...