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
Hi everyone,
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.
URL: http://pitweb.pitzer.edu/advancement/faculty-staff-gift-campaign/
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”>’;
the_sub_field(‘program_content_section’);
echo ‘</div></section>’;
endwhile;
else :
// no rows found
endif;
Thanks
Hi clburch,
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.
http://www.advancedcustomfields.com/blog/acf-pro-v5-1-1-update/
“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 🙁
Thanks for your effort josephd. I just rolled back to 5.1 and the problem is gone. Waiting for 5.1.2.
The topic ‘Empty Repeater Field displays container’ is closed to new replies.
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 use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.