I have a post-type with a fieldset with different repeaters.
One of those repeaters is referenced in a calculated field. This works fine for one post.
On another post I can fill the referenced repeater and save without any issue. also I can fill in a certain amount of rows into other repeaters and save without any issue.
But there comes a point, where filling one more row into one of the repeaters (not referenced in calc-fields) makes it impossible to save the whole post.
Throwing following error messages:
nvalid argument supplied for foreach() in …\calculated-fields-for-acf\src\Fields.php on line 66
nvalid argument supplied for foreach() in …\calculated-fields-for-acf\src\Fields.php on line 88
On another post, the same amount of rows filled into the repeaters does not cause any issue.
When I remove the formula from the calculated field, saving works again for all posts.
I was not able to find some common cause for this so far as the referenced repeater is not changed and its not happening for all posts.
This topic was modified 5 years, 4 months ago by polarracing.
I hope I fully understood your situation, because my response will assume a few things about your setup…
That said, this one is an easy fix, and without coding. You are getting the error, because the Calculated field is trying to calculate something that does not exist, which is the cases where the Calculated field cannot calculate because the field(s) that will be involved in the calculated field does not exist…
In ACF edit your field group, and for the Calculated Field, add a Conditional Logic that all your other fields involved in the Calculation should have any value.
If you are not sure what I meant for all the above, let me know, and I’ll make a short demo video for you.
Hi,
sorry, but I don’t think this is the issue. I checked that. There are no fields calculated that have no value.
I guess my description was not pretty understandable.
Following setup:
repeater_field_1 – holding values to calculate.
When filled, all is fine.
repeater_field_2 – holding other values – not used in calculated field.
I can add some values without any issue (i.e. 5).
If I add the 6th value to repeater_field_2 the error appears. No changes to the repeater_field_1 has been made.
So if its the issue you describe, why should it only appear if another repeater gets a certain amount of values and the repeater calculated is not touched at all?
I think there is some misunderstanding in the terminology. I think and hope that when you say “repeater_field_1” you don’t actually mean an actual Repeater field, but a Repeater’s Sub field, in other words a field inside a Repeater Field.
So, if I’m understanding you correctly, you still want to have the option to create Repeater field record and at the same time having the option to not have any values in the numeric field that will be involved in the calculation. If that’s the case, this is not possible right now, at the very least you can set a default value when creating your field group in ACF, or manually by setting a value, any numeric value that is in that field, it cannot be empty. Having the plugin guessing a default value is near impossible, because if the calculations involved is a simple addition, a default value of 0 would be fine, but what if the calculation is multiplication or division, a default value of zero would be “catastrophic” to the calculated results.
For the example I spoke about in my first response, here is a short video explanation. But unlike your example, because the calculation involved is simple addition, I can get away with a default value of 0. That said, I have set it up in a way that the Calculated Field makes an appearance ONLY if the Repeater Fields has any records.
All you wrote is clear and understandable, but does not cover the issue. And I understand your approach, that was the same points I was assuming first as well.
That’s my scenario:
repeater1 with field A, ….
The field A is referenced outside the repeater with a calculated field count(repeater1.fieldA).
repeater2 with fields X,Y,Z. None of those fields is referenced in any calculated field.
Steps:
– Create a new post, fill in values into repeater1 – all works fine. Calculated field is calculated and post can be saved.
– Then filling in values into repeater2 – no issue, post can be saved.
– Adding more values to repeater2 and at some point it does not work anymore – the error message appears and I can not save the post any more.
To be clear, in repeater1 nothing is changed and in repeater2 all field are filled as the previous records.
There is no field used in calculated fields left empty when this appears. In the repeater2 – the one I fill – is not even a single field used for calculations. And the repeater with the fields used for calculation is not touched.
Currently I have changed my setup, so its not mission critical any more – but I will will investigate further after finishing my current project.
Hi,
sorry, but currently not. I have removed the calculated fields from my project at the moment – as I need to finish it and the deadline is coming closer.
After the project is done I will set up another testing environment and retest the issue as I want to use the calculated fields at a later stage.
The way I deal with this “issue” is to assign a default value of 0 (zero), and ensuring that a null value is not allowed, while creating my numeric fields that will be part of a calculation, during the Field Groups creation process in ACF.
Viewing 8 replies - 1 through 8 (of 8 total)
The topic ‘Invalid argument for foreach()’ is closed to new replies.