Support

Account

Home Forums Add-ons Repeater Field Nested Repeater w/ First Passing Variable to Second

Helping

Nested Repeater w/ First Passing Variable to Second

    • zuggle

    • March 23, 2021 at 12:46 pm

    Greetings. This is a nested repeater. The first repeater tells the second which ACF field to fetch and then is supposed to display its value in a table cell.

    The first part works—all of the proper table headers are displayed in separate tables based on the first repeater—but the second part does not work. I’ve even tried to put random text (like “test”) in between the tdtags but nothing appears.

    $fieldtofetch is the variable in the first repeater that informs which ACF field to fetch in the second repeater (e.g., “part_number”).

    Thanks for any help!

    if ( have_rows( 'product_table' ) ) : ?>    
        <?php while (have_rows('product_table')):
        the_row(); ?>       
            <table>
            <h3><?php the_sub_field('product_table_title'); ?></h3> 
            
            <?php if (have_rows('product_table_columns')): ?>
                <?php while (have_rows('product_table_columns')):
                the_row(); ?>
                    <?php $tcols = get_sub_field('product_table_column'); ?>
                        <th><?php echo $tcols['label']; ?></th>
                    <?php $fieldtofetch = $tcols['value']; ?>
                    
            <?php if (have_rows('product_table_products')): ?>
                <?php while (have_rows('product_table_products')):
                        the_row(); ?>
                    <?php $product_table_product = get_sub_field('product_table_product'); ?>
                    <?php if ($product_table_product): ?>
                        <tr><td><?php the_field($fieldtofetch); ?></td></tr>
                        
                    <?php
                        endif; ?>
                <?php
                    endwhile; ?>
                        
                    <?php
                endif; ?>   
                    
        <?php
            endwhile; ?>
            
        </table>
            
            <?php
        endif; ?>   
                    <?php
    endwhile; ?>
                        <?php
    endif; ?>
    • zuggle

    • March 24, 2021 at 12:53 am

    PS: I did try changing <?php the_field($fieldtofetch); ?> to <?php the_sub_field($fieldtofetch); ?> because I think that is correct but still no joy.

Viewing 2 posts - 1 through 2 (of 2 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.