Home › Forums › Add-ons › Repeater Field › Empty Repeater Field displays container
Note I also posted this at https://wordpress.org/support/topic/plugin-advanced-custom-fields?replies=1#post-6174170
I ran into an issue with Advanced Custom Fields where an empty container is displaying instead of the “else” statement after the content has been removed from the container. So to be clear it once had information but that information was deleted.
I’m pretty sure my has an error can anyone see my mistake in the php below?
<?php // check if the accordion repeater field has rows of data if( have_rows('accordion') ): ?> <?php // loop through the rows of data while ( have_rows('accordion') ) : the_row(); ?> <div class="section-container accordion content" data-section="accordion"> <section> <p class="title" data-section-title><strong><a href="#"><?php the_sub_field('accordion_title'); // accordion title acf ?></a></strong></p> <div class="content" data-section-content> <?php the_sub_field('accordion_content'); // accordion content acf ?> </div> </section> </div> <?php endwhile; else : // no rows found endif; ?>
I just sent in a support ticket with the same issue. I recently upgraded to pro from the 4.x line with the paid repeater add on. Even though I have no rows, it is still rolling as if there is content. I will paste my code below. When I did the upgrade, I did not notice this. I happened to update to 5.1.1 this morning, so it may just be an issue with the recent release. Or this was there on Monday when I upgraded from 4.x to 5.1 and I missed it.
$i = 0;
if( have_rows(‘program_content_sections’) ):
while ( have_rows(‘program_content_sections’) ) : the_row();
echo ‘<section class=”prog-section-‘ . ++$i . ‘”><div class=”wrap in-page”>’;
// no rows found
I updated to 5.1.1 this morning and didn’t consider that could be the issue. the blog states a fix to the repeater field.
“Field group: Fixed bug where sub fields were deleted when moving a repeater field to another group”
Perhaps that same fix is causing deleted fields to display null content. I poked around to create variables
$title = get_sub_field('accordion_title' ); // get the title $content = get_sub_field('accordion_content'); // get the content
That results in a 0 instead of empty space. Different error same problem the variable is empty.
I downgraded from ACF Pro 5.1.1 to 5.1.
Downgrading fixed the problem. I’ll wait until the next version to upgrade 🙁
I’m having this same issue with 5.1.1
Thanks for your effort josephd. I just rolled back to 5.1 and the problem is gone. Waiting for 5.1.2.
I just upgraded to 5.1.2 and this appears to be fixed. 😀
Thanks Legin76, I’m updating now 🙂
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re hard at work on ACF 6.1, and Beta 1 is now available 🚀— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.