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

    • rcpilot

    • December 28, 2018 at 5:51 am

    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)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.