Home › Forums › Add-ons › Repeater Field › Difficulty sorting on repeater sub-field › Reply To: Difficulty sorting on repeater sub-field
That’s because you put the code outside of the loop. It should be something like this:
// loop through repeater
if( $repeater ):
// initialize the position for later use
$position = '';
?>
<ul class="forms">
<?php foreach( $repeater as $i => $row ): ?>
<?php
// check if the current postion is changed
if( $position != $row['position'] ){
// set the current position
$position = $row['position'];
?>
<h2><?php echo $row['position']; ?></h2>
<?php } ?>
<li class="form"><?php echo $row['form_name']; ?>
<a href="<?php echo $row['document']; ?>" target="_blank">Download</a><?php if( $row['online'] ): ?> | <a href="<?php echo $row['online']; ?>">Fill out online</a><?php endif; ?>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); ?>
Because this is more related to PHP, kindly visit their community for further support.
I hope this helps 🙂
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.