I have an existing repeater custom field for videos that I’ve attached to a custom post type called ‘players’. We’ve added at least a hundred plus videos to various players.
The issue is now we’ve realized that this ‘videos’ custom field should really be a cpt so we can sort them and utilize them in different ways.
Is there any way to convert each of these videos into a new ‘video’ custom post type we created?
Thx for reply. At this point, I’d be happy if I could just convert the data from a repeater custom field in the ‘player’ cpt to a single oembed custom field in ‘video’ custom post type.
The only data that is currently in the repeater field is an oembed field.
I realize that extracting the data from the repeater field to single field is probably the complicated part, correct?
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.
I think it would be more efficient to create the new pages by hand than to automate it.
you said 100+ videos. If you have mulitple screens and you can past from one to the other creating new posts along the way and you are copying one field, someone being efficient with their time could speed through 30 to 60 new posts an hour. 2 to 4 hours would be less time then building automation that will be deleted when you’re done.
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
Helping others is a great way to earn karma, gain badges and help ACF development!