Support

Account

Home Forums Add-ons Flexible Content Field Migrating from repeater field to flexible content field Reply To: Migrating from repeater field to flexible content field

  • Hi @kyon147

    If you have the right code, I believe it won’t be hard. You can loop through the posts and use the update_field() function to update the new flexible content like this:

    $post_id = 99;
    $flex_field_key = "field_123456789";
    
    // Get the repeater values
    $repeater = get_field('repeater');
    
    // Create an array to store the new flexible values
    $flexible = array();
    
    // Loop through the repeater 
    foreach( $repeater as $row ){
    
        // Set the values
        $flexible[] = array(
            "flex_sub_field_1" => $row['repeater_sub_field_1'],
            "flex_sub_field_2" => $row['repeater_sub_field_2'],
            "acf_fc_layout" => "layout_1_name"
        );
    
    }
    
    // Update the new flexible field
    update_field( $flex_field_key, $flexible, $post_id );

    After the repeater field is copied correctly, you can delete it.

    Please don’t forget to backup your site and database first in case something bad happens.

    I hope this helps 🙂