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?