Support

Account

Home Forums Add-ons Repeater Field Sort of a repeater

Solved

Sort of a repeater

  • Hi Elliot,

    I know you have a tutorial for this (http://www.advancedcustomfields.com/resources/how-to/how-to-sorting-a-repeater-field/) but I’m a little confused. Once you get down to the last part

    foreach( $repeater as $row )
    {
    	// ...
    }

    what do you use to get the fields?

    I have this code below, but doesn’t bring back the first_name or last_name fields. It outputs the <li></li> elements just fine though, so it must be working. I did a print_r on $row and have posted an example of the dump below.

    Thanks in advance,
    R

    <?php $team_repeater = get_field('meet_the_team');
     foreach( $team_repeater as $key => $row ) {
     $column_id[ $key ] = $row['last_name'];
     } array_multisort( $column_id, SORT_ASC, $team_repeater ); ?>
     <ul>
     <?php foreach( $team_repeater as $row ) { ?>
       <li><?php the_sub_field('first_name'); ?>&nbsp;<?php the_sub_field('last_name'); ?></li>
    <?php } ?>

    Array ( [first_name] => Bob [last_name] => Johnston )

  • Hi @rdck

    In your final loop, you can access the data like so:

    
    <?php foreach( $team_repeater as $row ) { ?>
       <li><?php echo $row['first_name']; ?></li>
    <?php } ?>
    

    Thanks
    E

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Sort of a repeater’ is closed to new replies.