Home › Forums › Add-ons › Repeater Field › Loop else doesn't work
Hi everyone!
My code is almost perfect, just it has a mistake with the else loop that doesn’t work.
My code is the next:
<?php if(have_rows('otros_archivos')): ?>
<ul>
<?php while ( have_rows('otros_archivos') ) : the_row(); ?>
<ol><a href="<?php the_sub_field('antecedente'); ?>" target="_blank"><?php the_sub_field('antecedente'); ?></a><br/></ol>
<?php endwhile; ?>
</ul>
<?php else :
echo "<i>No se ha subido ningún antecedente aún.</i><br/>";
endif;
?>
Thanks in advance!
Hi!
So the else line code doesn’t work because the rows are empty. That must be it… I try many times to edit this code without success.
Please can you help to edit my code for that else part works well?
Thanks in advance!
Hi Millano,
I used your exact and got everything working. Kindly send me the url and credentials to your test server so that I may assist you debugging.
Hi again!
Finally I edit my code and works!
This is the code:
<?php if(have_rows('otros_archivos')):
while (have_rows('otros_archivos')) : the_row();
$post_object = get_sub_field('antecedente');
if($post_object):
$post = $post_object; setup_postdata($post); ?>
<a href="<?php the_permalink(); ?>" target="_blank"><?php the_title(); ?></a>
<br/><br/>
<?php wp_reset_postdata();
else:
echo "<i>No se ha incluido ningún antecedente aún.<br/></i>";
endif;
endwhile;
endif; ?>
Anyway thanks for your help James.
I hope this code can help someone!
The topic ‘Loop else doesn't work’ 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.