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;
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.