Support

Account

Home Forums Add-ons Repeater Field Repeater field, inside Group field, cannot add entries programmatically

Helping

Repeater field, inside Group field, cannot add entries programmatically

  • Hello all,

    I’ve started using ACF for a project of mine that works as business directory. For each business (place) I want to register the working days and hours.

    The structure I created is like this:

    [Group Field] Name of the day (Monday, Tuesday, etc)
        [True/False Field] Open All Day
        [True/False Field] Closed All Day
        [Repeater Field] Time Entries
            [Time Picker Field. Display/Return Format H:i] Open Time
            [Time Picker Field. Display/Return Format H:i] Closing Time
    

    Using code to create entries, I’ve managed to set the Open/Closed All Day fields, but I am not able to set the Time Entries.

    I’ve tried several different formats of this code:

    
    foreach ( $workingHours as $workingHour ) {
        $day = $workingHour->en;
    
        // Update all day open/closed fields
        update_field( "{$day}_all_day_open", $workingHour->allDayOpen, $post_id );
        update_field( "{$day}_all_day_close", $workingHour->allDayClosed, $post_id );
    
        if (
            true === $workingHour->allDayOpen ||
            true === $workingHour->allDayClosed
        ) {
            continue;
        }
    
        $time_entries = [];
        if ( ! empty( $workingHour->workingHours ) ) {
            foreach ( $workingHour->workingHours as $hour ) {
                $time_entries[] = [
                    "open_time"    => $hour->opening,
    		"closing_time" => $hour->closing,
                ];
            }
        }
    
        update_field( "{$day}_time_entries", $time_entries, $post_id );
    }
    

    Can someone help fix that issue?

  • — UPDATE —

    I’ve tried also with the repeater field key as selector param and didn’t worked.

    I’ve also tried the add_row like this:

    
    add_row(
        $repeater_id,
        [
            "open_time"    => $hour->opening,
            "closing_time" => $hour->closing,
        ],
        $post_id
    );
    

    And still, doesn’t work.

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

You must be logged in to reply to this topic.