Support

Account

Home Forums Add-ons Repeater Field Repeater loop in a wp_query loop Reply To: Repeater loop in a wp_query loop

  • @john thank you so much for all your effort. I tried your solution, and some others – and finally it worked. It seems that the main error was that reset_postdata was used on the wrong loop. So here is the code that is working

    <?php
    	$thistitle = get_the_title();
    	$args = array( 'post_type' => 'navigation', 'pagename' => 'Top navigation' );
    	$loop = new WP_Query( $args );
    
    	while ( $loop->have_posts() ) : $loop->the_post();
    
    	if ( have_rows('navigation') ):
    	    while ( have_rows('navigation') ) : the_row();
    			if ( get_sub_field('mega_menu_active')) {
    
    				$navitemID = get_sub_field('masterside', false, false);
    
    					$subargs = array( 'post_type' => 'navigation', 'page_id' => $navitemID);
    					$subloop = new WP_Query( $subargs );
    
    					while ( $subloop->have_posts()) : $subloop->the_post();
    				        if( have_rows('mega_menu')):
    				            while (have_rows('mega_menu')) : the_row();
    				              echo get_sub_field('menu_overskrift');
    				                while (have_rows('mastersidelinks')) : the_row();
    				                  $subnavitemID = get_sub_field('masterside_sub_links', false, false);
    				                  echo get_the_title($subnavitemID);													echo get_the_permalink($subnavitemID);
    				                endwhile;
    												
    			              endwhile;
    				        endif;
    							$loop->reset_postdata();
    					endwhile;
    				} else {
    					include(locate_template('templates/navigation/navigation-top.php'));
    				}
    	    	endwhile; else : endif; endwhile;
    	?>