Hi Guys,
I’m having trouble with the ACF Repeater and Post object.
I have a CPT loop and I want a repeater within the loop displaying a post type. But all I seem to get is the first row. If I use the same repeater outside the loop it does work correctly. Can someone please help me?
Loop:
$args = array( 'post_type' => 'slides' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php if(get_field('type_pagina') == "Trainingen"): ?>
<div class="training-container">
<div class="trainingen-inner">
<?php if(get_field('trainingen')): ?>
<?php while ( has_sub_field('trainingen') ) : the_row(); ?>
<?php $post_object = get_sub_field('training');
if( $post_object ):
$post = $post_object;
setup_postdata( $post ); ?>
<?php the_title(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif;?>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
See my explanation here for why this is happening https://support.advancedcustomfields.com/forums/topic/problema-withe-repeater-item/ and let me know if you have any questions.
Thanks man, that works like a charm! Hero of the day award to you!