• Resolved M1chel

    (@m1chel)


    Hi, how do I display nested repeaters?

    for instance:
    I created a a repeater named ‘town’ and a repeater called ‘places’. ‘places’ are part of the fields of ‘town’ but I don’t know how to display them for each ‘town’ entry.

    I tried a loop but it displays all the entries of ‘places’ and not just the ones of their parent post. (town = luoghi and places = consigliati)

    <section class="luoghi_da_visitare">
        <ul> 
            <?php
                $mypod = pods( 'luogo' ); 
                
                $mypod->find();
             
                // Loop through the items returned.
                
             while ( $mypod->fetch() ) {
                ?>
            <li class="luogo_item">
                <div class="luogo_img">
                     <img src="<?php    echo $mypod->display( 'immagine_luogo' ); ?>" alt="">
                     </div>
                <div class="luogo_testo">
                <a href="<?php    echo $mypod->display( 'sito_turismo' ); ?>"><?php    echo '<h3>' . $mypod->display( 'name' ) . '</h3>'; ?></a>
               
                    <?php    echo $mypod->display( 'descrizione_del_luogo' ); ?>
                    <a href="<?php the_permalink(); ?>" class="button">Scopri di più</a>
                    <div class="consigliati">
                        <h4>Consigliamo</h4>
                        <ul>
                        <?php
                $consigliati = pods( 'consigliati' ); 
                
                $consigliati->find();
             
                // Loop through the items returned.
                
             while ( $consigliati->fetch() ) {
                ?>
                            <li>
                                <a href="<?php    echo $consigliati->display( 'link_al_posto' ); ?>"><?php    echo $consigliati->display( 'name' ); ?></a>
                            </li>
                            <?php
                } //endwhile  
                ?>   
                        </ul>
                    </div>
                </div>
                
            </li>
                <?php
                } //endwhile  
                ?>        
            
        </ul>
    </section>
Viewing 1 replies (of 1 total)
  • Plugin Author Coding Panda

    (@codingpanda)

    Hi @m1chel

    Please try using pods_field( ‘pods_name’, ‘post_id’, ‘field_name’ ).

    
    $consigliati = pods_field( 'luogo', $mypod->display( 'id' ), 'consigliati'); 
    foreach( $consigliati as $place ){
        echo $place['name'] . '<br/>';
    }
    

    instead of

    
    $consigliati = pods( 'consigliati' );             
    $consigliati->find();
    $consigliati->fetch()
    

    I assumed “consigliati” is the field name for the repeater field as well.

    I will suggest using pods_field for the towns as well.

Viewing 1 replies (of 1 total)
  • The topic ‘displaying nested repeaters’ is closed to new replies.