campusboy87
10/30/2018 - 5:47 PM

acf_fields_replace_example.php

<?php

add_action( 'init', function () {
    if ( ! isset( $_GET['acf-convert'] ) ) {
        return;
    }

    $posts = get_posts( [
        'post_type'   => 'event',
        'numberposts' => - 1,
    ] );

    foreach ( $posts as $key => $post ) {
        $blocks = get_field( 'event_choice_blocks', $post->ID );
        $time   = get_field( 'event_data_time', $post->ID );

        if ( is_array( $blocks ) && in_array( 'program', $blocks ) ) {
            $value_old = get_field_object( 'program', $post->ID )['value'];

            // save a repeater field value
            $field_key = "field_5bd81da872c0b";

            if ( $value_old ) {
                $value_new = [
                    [
                        'date' => mysql2date( 'Ymj', $time ),
                        'day'  => $value_old,
                    ],
                ];

                update_field( $field_key, $value_new, $post->ID );
            }
        }

        delete_field( 'program', $post->ID );
    }
}, 999 );