I have a Custom Post Type with a repeater field with 5 subfields. I need to rebuild these posts so that the subfields are normal fields without copying and pasting. They both the repeater and fields are showing in the post and have the same names.
Is there a way of going this? I have 60 odd posts on 8 different websites that need updating so something a little more automated will be ideal.
The repeater and the top level field are not named the same in the database and they have different field key references because they are two different fields.
First, the only way you can safely move the values is if there is only a single row in the repeater with these 5 fields, which kinda kills the purpose of using a repeater. If there can be multiple rows then you’d need to loop over them all and concatenate all the values or you’d just loose them.
If this is the case you would need to create a function that
1) Get all of the posts
2) Loops over the repeater in each post
3) Gets the value from each sub field
4) Updates the corresponding field using update_field($field_key', $value, $post_id). You need to use the field key rather than the field name because the fields may not exist when you update them.
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users