Support

Account

Home Forums Add-ons Repeater Field Why we need check have_rows('parent_field') two times? Reply To: Why we need check have_rows('parent_field') two times?

  • For the same reason that in WP you do

    
    if (have_posts()) {
      while(have_posts()) {
        the_post();
      }
    }
    

    What if you want to do something outside the while loop but only if there are rows? What if you want to do something different if there are not rows?

    
    if (have_rows('field')) {
      // do something here before the loop
      while(have_rows('field')) {
        the_row();
      }
      // do something here after the loop
    } else {
      // do something different if there are not rows
    }
    

    Just like you can skip if (have_posts()) you can skip if(have_rows()) if you’re sure you don’t care what happens if there are none.