Home › Forums › Add-ons › Flexible Content Field › Convert Repeater to Flexible field — after content's been added › Reply To: Convert Repeater to Flexible field — after content's been added
If the flex field has the same name as the repeater and all the sub fields of the first layout are exactly the same as the old sub fields then you need to do something like this
// query all of the posts of the post type
$args = array(/* your query args here */);
$query = new WP_Query($args);
while ($query->have_posts()) {
$query->the_post();
// get the number of rows in the array
$rows = get_post_meta($post->ID, 'repeater_field_name');
// create an array containing the first layout $rows times
$value = array_fill(0, $rows, 'first_layout_name');
// update with the new value
update_post_meta($post->ID, 'repeater_field_name', $value);
}
I think this would need to be done after changing the field type but before attempting to update any posts that use the field.
This can probably also be done with straight db queries, but I’m not sure how to do that.
As always, when making large changes to the database always back it up first.
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.