
Hi at all,
I have a problem with nested Repeater Fields. I tried and searched for hours but didn’t find a solution, so I hope you can help me.
My homepage is a singlepager where the contents are selected via a Post Object Field (new-content) within a Repeater field (content-order) on an Option Page.
The selected contents can have a page Layout with Tabs, where each Tab is also a Post Object Field (tab-content) within a Repeater Field (tabs).
The Problem is, that only the first Element of the Post Object Field in the Tabs is displayed. Can someone help me?
The Code looks like this:
<?php
if( have_rows('content-order', 'option') ):
while ( have_rows('content-order', 'option') ) : the_row();
$post_object = get_sub_field('new-content', 'option');
if( $post_object ):
// override $post
$post = $post_object;
setup_postdata( $post );
?>
<?php the_content(); ?>
<?php if( have_rows('tabs') ): ?>
<?php
while ( have_rows('tabs') ) : the_row();
$post_object = get_sub_field('tab-content');
if( $post_object ):
// override $post
$post = $post_object;
setup_postdata( $post );
?>
<?php the_title(); ?>
<?php wp_reset_postdata(); endif; endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); endif; endwhile; endif; ?>
The problem is that you cannot have multiple post loops the way you have them set up.
Please see my explanation of the problem here https://support.advancedcustomfields.com/forums/topic/nested-post-object-fields/#post-48227
You need to loop through the second relationship field in some other way than using setup_postdata()/reset_postdata() and you’ll need to use a different method of getting the values from the fields.