Home › Forums › Add-ons › Repeater Field › Display Repeater field with Post-Option field
Hello, can you please help me with a repeater field? I would like to display a table with the data, but it show only the first entry from second field (aroma). The “Aroma” field is a post-option field inside the Repeater. i hope you understand what i wont.
Sorry for my bad english.
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Menge</th>
<th scope="col">Aroma</th>
</tr>
</thead>
<tbody>
<tr>
<?php if( have_rows('aromen') ): ?>
<?php while( have_rows('aromen') ): the_row();
// vars
$menge = get_sub_field('menge');
?>
<td><?php echo $menge ?></td>
<td><?php $post_object = get_field( 'aroma' ); ?>
<?php if ( $post_object ): ?>
<?php $post = $post_object; ?>
<?php setup_postdata( $post ); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php wp_reset_postdata(); ?>
</td>
<?php endif; ?>
</tr>
</tbody>
</table>
<?php endwhile; ?>
<?php endif; ?>
Nobody can help me?
Whats wrong with my code?
<table class="table table-bordered">
<?php
$post_objects = get_field('aromen');
if( $post_objects ): ?>
<?php foreach( $post_objects as $post_object): ?>
<tr>
<td> <?php the_field('menge'); ?> </td>
<td> <?php echo get_the_title($post_object->ID); ?> </td>
</tr>
<?php wp_reset_postdata(); ?>
<?php endforeach; ?>
<?php endif;
?>
</table>
Hello,
I’m fairly new here, but can say that bumping your post is probably not the best way to get an answer. Just wait, if someone is able to help, they will.
I will try to help.
Do you have the Post_Object Return Format set to return the PostID or the Post Object?
Right after your get_field, try printing out the $post_objects array and see if there is data in the returned array, and please provide the results that are displayed on the page.
There is nothing wrong with the code that you posted that I can see. The issue could be the context that your code is running in. What is happening before the code you posted? Are you doing a custom query and loop on the results of that query?
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 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.