Support

Account

Home Forums Add-ons Repeater Field Difficulty sorting on repeater sub-field Reply To: Difficulty sorting on repeater sub-field

  • Hi @brotsky_pixie

    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 🙂