Support

Account

Home Forums Add-ons Repeater Field Post Objects in a Repeater

Helping

Post Objects in a Repeater

  • Hi. I’m having trouble to display post objects in a repeater. I think the problem is around the secound while loop. Someone has any Ideas?

    <?php if( have_rows('repeater') ): ?>
    <?php while( have_rows('repeater') ): the_row(); 
        // vars
        $repeater = get_sub_field('repeater'); ?>
        <?php $repeaterGroup = get_sub_field('repeater_group'); ?>
        <div class="box25-75">
            <div class="col col1">
                <?php $colLeft= $repeaterGroup['left_col']; ?>
                <div class="text">
                    <p class="text-center">
                        E: <a href="mailto:<?php echo $colLeft['email']; ?>"><?php echo $colLeft['email']; ?></a>
                        T: <?php echo $colLeft['telefon']; ?>
                    
    
                </div>
            </div>
            <div class="col col2">
                <div style="margin-top: 40px;">
                    <?php
                      $args = array(
                        'post_type' => 'html5-blank',
                        'post_status' => 'publish',
                        'posts_per_page' => '100',
                      );
                      $wp_query = new WP_Query( $args );
                      if ( $wp_query->have_posts() ) : ?>
                            <?php while ( $wp_query->have_posts() ) : $wp_query->the_post();
                              // Set variables
                              $title = get_the_title();
                              $description = get_the_content(); 
                              $field = get_field_object('autor');
                              $colors = $field['value'];
                              $date = get_the_date( 'd.m.Y' );
                              // Output
                              ?>
                                <?php // show something ?>
                                <?php $wp_query->reset_postdata(); ?>
                            <?php endwhile; ?>
                        <?php endif; ?>
                </div>
            </div>
            <div class="clear"></div>
        </div>
    <?php endwhile; ?>
    <?php endif; ?>
  • Hi,

    When you have a loop in a loop, the function like get_the_content() or get_field_object(‘autor’) dont know if they must use the ID of the first “looped” object or the second one …

    To solve it, get the id in variable and use it to clearly indicate which object is focused :

    
    if ( $wp_query->have_posts() ) : ?>
             <?php while ( $wp_query->have_posts() ) : $wp_query->the_post();
                              // Set variables
                              $id = get_the_ID()
                              $title = get_the_title($id );
                              $description = get_the_content($id ); 
                              $field = get_field_object('autor', $id );
                              $colors = $field['value'];
                              $date = get_the_date( 'd.m.Y' );
                              // Output
                              ?>
                                <?php echo $colors;  ?>
                                <?php $wp_query->reset_postdata(); ?>
              <?php endwhile; ?>
       <?php endif; ?>

    Hope it helps.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Post Objects in a Repeater’ is closed to new replies.