Home Forums ACF PRO Display repeater field in descending order


Display repeater field in descending order

  • i am using the following code to get displayed the following text :

    • rom 1
    • rom 2
    • rom 3

    but i want to display all this in descending order as :

    • rom 3
    • rom 2
    • rom 1
    <?php if( have_rows('rom') ): ?>
        <?php while( have_rows('rom') ): the_row(); ?>
            <li><?php the_sub_field('rom_name'); ?></li>
        <?php endwhile; ?>
    <?php endif; ?>

    This is a small example i have considered, but im planning to do a big task using this.

    or if not this then what could be done so that when i add a new sub field in the repeater field, then the new added field is placed on the top rather than going at the last?

  • Hi @harshmeet

    Please read over the following article:

    This should help understand how to sort the repeater field array


  • Try this

    <div class="main-div">
    <?php $outs = array(); if( have_rows('main_field') ): $i = 0;        
                while ( have_rows('main_field') ) : the_row(); ob_start(); $i++; ?> 
    <div class="question-answer-template">
    <p><?php the_sub_field('sub_feild');?></p>
    <?php $outs[] = ob_get_clean(); endwhile; 
            else :
            $outs = array_reverse($outs);
            echo implode($outs);
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Display repeater field in descending order’ is closed to new replies.