Advanced Custom Fields nested repeaters output


#1

Hi!

I’m slowly getting to understand ACF and nested repeaters, but I am having trouble displaying it on my site.

The “Menu Sections” displays, but I must be doing something wrong with the menu items, because it wont display them…

This is what I have in a code block:

https://pastebin.com/6Nid7kVd?fbclid=IwAR3LOdsoqmk-zVET_cWn725zxfW5FiSvAbZ_KDzwly3zTFNkAQsroFv5v8g

Thankful for any tips !


#2

It displays “Ingen retter funnet” which is norwegian for “No dishes found”, even though I have added dishes. So I think there must be something I did wrong in the second section of php…


#3

Code posted were would help. I dont have access to pastebin while at work.


#4
<?php

// check if the repeater field has rows of data
if( have_rows('menu_sections') ):

 	// loop through the rows of data
    while ( have_rows('menu_sections') ) : the_row();?>

		<h2>
        <?php the_sub_field('section_title');?>
		</h2>  

<?php if(get_sub_field('menu_description')) ?>


  
<?php
    endwhile;

else :

    echo "Ingen retter funnet";

endif;

    ?>

            <?php

            // check if the repeater field has rows of data
            if( have_rows('section_items') ):

                // loop through the rows of data
                while ( have_rows('section_items') ) : the_row(); ?>

                    <h3> 
                    <?php the_sub_field('rett_navn'); ?>
                    </h3>
                    <p>
                    <?php the_sub_field('rett_beskrivelse'); ?>
                    </p>
                    <p>
                    <?php the_sub_field('rett_allergener'); ?>
                    </p>
                    <p>
                    <?php the_sub_field('rett_pris'); ?>
                    </p> 

    <?php
            endwhile;

        else :

          echo "Ingen rader funnet";

        endif;

        ?>

#5

Is this okay to read? Didnt find an option to paste raw code.

thank you in advance!


#6

Okay, this is WordPress…

Based on what the code is and what you said, I would check the DB and see what the repeater name is listed as; if it isn’t exact, then it would cause 0 rows to be returned.


#7

Yes, sorry for not specifying that. I got some tips that I was closing an opening an “if” without closing the first loop… if that makes sense to you, hehe