Home Forums Add-ons Repeater Field Loop else doesn't work


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')): ?>
    <?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; ?>
    <?php else :
    	echo "<i>No se ha subido ningún antecedente aún.</i><br/>";

    Thanks in advance!

  • This reply has been marked as private.
  • 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');
    			$post = $post_object; setup_postdata($post); ?>
    			<a href="<?php the_permalink(); ?>" target="_blank"><?php the_title(); ?></a>
    			<?php wp_reset_postdata();
    			echo "<i>No se ha incluido ningún antecedente aún.<br/></i>";
    endif; ?>

    Anyway thanks for your help James.

    I hope this code can help someone!

  • This reply has been marked as private.
  • This reply has been marked as private.
Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Loop else doesn't work’ is closed to new replies.