Home › Forums › ACF PRO › Change existing repeater field data to new custom post type › Reply To: Change existing repeater field data to new custom post type
What you need to do is to create a function that run when any page is loaded. When I need to do this I generally create an init action.
The operation will likely time out the site, but you can work around this. To do this you need to have some value in the posts that changes indicating that the changes for a post have been completed, in your case, you will probably need two marker values. One that a post has been completed and then one for each row of the repeater on that post that says the row has been completed.
Then you do a query for all posts that do not have the “completed” flag set. You loop over those posts and then loop over the repeater. In the repeater loop you skip the rows that have been completed. For the uncompleted rows you use wp_insert_post() to create a new post and then use the acf function update_field(), using the field key to copy the value of any ACF fields. When you complete this you update the flag for each row. When you complete the loop over the rows you update the completed flag for the post.
Like I said, with all of this it will probably time out. You load a page and if it times out you wait a bit, more than likely your server will continue to process in the background after the browser times out. Wait a while and load the page again and see if it times out, rinse, repeat. When the page load no longer times out then everything has been copied.
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.