I have a repeater field that has been working just fine. However now after a few weeks I’ve gone back to edit the repeater and when I add a new row to the first position it doesn’t display that first row. I just get rows 2-last. If I add another row at the top then I can see what was previously in the first position, but again I am only getting rows 2-last. I’m using:
<?php while(has_sub_field('region_highlight', $post_object1->ID)):?>
<?php the_sub_field('region_highlight', $post_object1->ID); ?>
<?php endwhile; ?>
However if I check it with:
print_r( get_field('region_highlight', $post_object1->ID) );
It will return that first row:
[0] => Array
([region_highlight] => first row)
Any ideas on what is going wrong?
Hi @JRKeck
The has_sub_field
function expects the field name to be the ‘repeater’ field, not the ‘sub’ field. Perhaps this is the issue
The repeater field and the sub_field have the same name. Is this causing the problem? Unfortunately if I try to change either now I lose the data in the fields.
Hi @JRKeck
It is untested, but extremely likely that the issue us caused by naming the parent and child the same name.
To get around this, I would advise not to use the has_sub_field loop. Instead, use get_field to get the repeater field as an array and use simple PHP foreach to loop through the rows.
There are examples of this on the repeater field documentation page