Home › Forums › Add-ons › Repeater Field › Repeater not working › Reply To: Repeater not working
Hi John, I got working the first loop, now Im getting the values for the “temas” but theres printing another value duplicated by 3 on each subfield right next to “temas_generales” and “temas_especificos”. I dont know where is coming from, here is the code (sorry for just pasting the code before)
“temas” is a repeater that has 2 subfields “tema_general” and “tema_especifico” both are Post Object defined as Post Object in the Return Format field
if( have_rows('cobertura') ): ?>
<p class="font-arial fs-13 hint-text">País(es)<br><strong>
<?php while ( have_rows('cobertura') ) : the_row();
$myposts = get_sub_field('pais');
if( $myposts ): foreach( $myposts as $post_object):
echo get_the_title($post_object->ID);
endforeach;
endif;
echo "</strong></p>";
endwhile;
else :
if ($pais != '') { ?><p class="font-arial fs-13 hint-text">País<br><strong><?php echo $pais; ?></strong></p><?php }
endif;
if( have_rows('temas') ): ?>
<p class="font-arial fs-13 hint-text">Tema(s)<br><strong>
<?php while ( have_rows('temas') ) : the_row();
$post_objects = get_sub_field('tema_general');
if( $post_objects ): ?>
<?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<?php the_title(); ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif;
$post_objects = get_sub_field('tema_especifico');
if( $post_objects ): ?>
<?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<?php the_title(); ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif;
echo "</strong></p>";
endwhile;
else :
endif; ?>
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.