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 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.