Support

Account

Home Forums Bug Reports Breaking out of a `have_rows` loop strangely affects the next `have_rows` loop

Unread

Breaking out of a `have_rows` loop strangely affects the next `have_rows` loop

  • Basically, I have some code that should work like this:

    
    <?php while ( have_rows( 'first_section' ): the_row(); ?>
      ...
      Display some stuff
      ...
      <?php if ( get_row_index() > 6 ) break; ?>
    <?php endwhile; ?>
    
    <?php while ( have_rows( 'second_section' ): the_row(); ?>
      ...
      Display some stuff
      ...
    <?php endwhile; ?>
    

    However, the second section doesn’t display, and I’m pretty sure it has something to do with breaking out of the previous loop, as if I remove just the break statement everything’s fine.

    Otherwise, I can sort of fix it by adding this just before the second section:

    
    <?php echo ( have_rows( 'second_section' ) ) ? "Not Broken!" : "Broken!"; ?>
    

    But, that also presents the weird behavior of echoing “Broken!” and then actually displaying the second section. So, somehow calling have_rows() twice fixes the rigging of the loop that was broken by the break, while also inappropriately returning false the first time it’s called.

Viewing 1 post (of 1 total)

The topic ‘Breaking out of a `have_rows` loop strangely affects the next `have_rows` loop’ is closed to new replies.