wordpress acf form display data orderby order_no

190 views Asked by At

For ACF form plugin, I used field group function which contains 10 fields, and loop to display in post like below:

<?php $fields = get_field_objects($post_id); 
if( $fields)
{
    foreach( $fields as $field_name => $field )
    {
        if($field['type']=='text' || $field['type']=='textarea' ){
            echo '<li>';
            echo '<label>' . $field['label'] . '</label>';
            echo '<span>' . $field['value'] . '</span>';
            echo '<span>' . $field['order_no'] . '</span>';
            echo '</li>';
        }
    }
}?>

Now I want to sort it by order_no, how can I do it?

1

There are 1 answers

1
radscheit On BEST ANSWER

You could try something like that before you print out:

function objectSort( $a, $b ) {
return $a->order_no == $b->order_no ? 0 : ( $a->order_no > $b->order_no ) ? 1 : -1;
}

usort( $fields, 'objectSort' );

Note: This is not meant to be a full correct code, I just want to give you an idea for the solution.