Home Forums Add-ons Repeater Field How retrieve repeater's row ids from foreach() loop


How retrieve repeater's row ids from foreach() loop

  • Hello everyone,

    Usually, Iretrieve the row ID from the loop using get_row_index() function as per documentation.

    However, as I want to order rows by sub_fields (startdate), I have to use a foreach() and then use an array_multisort(). But in the foreach() I cannot access the function get_row_index() anymore, so is there another method to achieve the same results, namely results ordered by startdate and having access to the row ID.

    Here is my code, thank you.

    $retraites = get_field('retraites', 157);
    foreach($retraites as $key => $retraite) :
        $column_id[$key] = $retraite['startdate'];
    array_multisort($column_id, SORT_ASC, $retraites);
    foreach($retraites as $retraite) : 
        $startdate = date('Ymd', strtotime($retraite['startdate']));
        $enddate = date('Ymd', strtotime($retraite['enddate']));
        if($startdate > date('Ymd')) :
            date_i18n('d M Y', strtotime($retraite['startdate']));
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.