Support

Account

Home Forums Add-ons Repeater Field Repeater not working Reply To: Repeater not working

  • 
    <?php 
      if( have_rows('temas') ) { 
        ?>
          <p class="font-arial fs-13 hint-text">Tema(s) general(es)<br><strong>
            <?php 
              // keep a count of tema_especifico
              $tema_especifico = 0;
              while( have_rows('temas') ): 
                the_row();
                // see if row has tema_especifico
                if (get_sub_field('tema_especifico')) {
                  // yes add to count
                  $tema_especifico++;
                }
                $post_object = get_sub_field('tema_general');
                if( $post_object ): 
                  // override $post
                   $post = $post_object;
                  setup_postdata( $post );
                  ?>
                  <li><?php the_title(); ?></li>
                  <?php 
                    wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
                endif;
              endwhile;
            echo "</strong></p>";
      }
      
      if( have_rows('temas') && $tema_especifico ) { 
        // only show this section if tema_especifico were found during first loop
        ?>
          <p class="font-arial fs-13 hint-text">Tema(s) especifico(s)<br><strong>
            <?php 
            while( have_rows('temas') ): 
              the_row();
              $post_object = get_sub_field('tema_especifico');
              if( $post_object ):
                // override $post
                $post = $post_object;
                setup_postdata( $post );
                ?>
                  <li><?php the_title(); ?></li>
                <?php 
                wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
              endif;
            endwhile;
          echo "</strong></p>";
      } else {
        if ($tg != '') {
          ?>
            <p class="font-arial fs-13 hint-text">
              Temática general <br><strong><?php echo $tg; ?></strong>
            </p>
          <?php
        } 
         if ($te != '') { 
          ?>
            <p class="font-arial fs-13 hint-text">
              Temática específica<br><strong><?php echo $te; ?></strong>
            </p>
          <?php 
        }
      } 
    ?>