Support

Account

Home Forums ACF PRO Change existing repeater field data to new custom post type

Solved

Change existing repeater field data to new custom post type

  • Hi –
    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?

  • It might be possible to do this in code but it’s going to be extremely complicated.

    What data is in the repeater? What data will be added to the new CPT? How will the data change on the “Players” CPT?

  • 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.

  • Hi John,

    I appreciate you taking the time to assist me on this, but unfortunately, I think it’s beyond my capabilities. Perhaps I can hire someone to do this for me?

    thx
    -matt

  • 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.

  • Yes makes sense.

    I guess I’ll see if I can figure out a way to display all of the video fields used

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.