Home › Forums › Add-ons › Repeater Field › Post Objects in a Repeater
Hi. I’m having trouble to display post objects in a repeater. I think the problem is around the secound while loop. Someone has any Ideas?
<?php if( have_rows('repeater') ): ?>
<?php while( have_rows('repeater') ): the_row();
// vars
$repeater = get_sub_field('repeater'); ?>
<?php $repeaterGroup = get_sub_field('repeater_group'); ?>
<div class="box25-75">
<div class="col col1">
<?php $colLeft= $repeaterGroup['left_col']; ?>
<div class="text">
<p class="text-center">
E: <a href="mailto:<?php echo $colLeft['email']; ?>"><?php echo $colLeft['email']; ?></a>
T: <?php echo $colLeft['telefon']; ?>
</div>
</div>
<div class="col col2">
<div style="margin-top: 40px;">
<?php
$args = array(
'post_type' => 'html5-blank',
'post_status' => 'publish',
'posts_per_page' => '100',
);
$wp_query = new WP_Query( $args );
if ( $wp_query->have_posts() ) : ?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post();
// Set variables
$title = get_the_title();
$description = get_the_content();
$field = get_field_object('autor');
$colors = $field['value'];
$date = get_the_date( 'd.m.Y' );
// Output
?>
<?php // show something ?>
<?php $wp_query->reset_postdata(); ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<div class="clear"></div>
</div>
<?php endwhile; ?>
<?php endif; ?>
Hi,
When you have a loop in a loop, the function like get_the_content() or get_field_object(‘autor’) dont know if they must use the ID of the first “looped” object or the second one …
To solve it, get the id in variable and use it to clearly indicate which object is focused :
if ( $wp_query->have_posts() ) : ?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post();
// Set variables
$id = get_the_ID()
$title = get_the_title($id );
$description = get_the_content($id );
$field = get_field_object('autor', $id );
$colors = $field['value'];
$date = get_the_date( 'd.m.Y' );
// Output
?>
<?php echo $colors; ?>
<?php $wp_query->reset_postdata(); ?>
<?php endwhile; ?>
<?php endif; ?>
Hope it helps.
You must be logged in to reply to this topic.
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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.