Why Would You Get This Problem?Sometimes when developers build the websites using ACF they might want to consider using groups or repeaters to be displayed within a section. Think of like looping all of these repeating elements within a page, only realising that later on the requirements have changed to display this onto another page and another and another.As such you might not even want to repeater.In fact sometimes using a repeater can be a mistake. You might want to use that as a custom post type rather than as a repeater.So here is one solution where in you can make that turning point from a repeater found in one page, towards a custom post type.
The function consists of an action hook called
acf/save_post meaning that we want to run this function whilst we are saving the post.
We pick ID containing the repeater — in this example
1234 and prepare the migration by retrieving all the custom post types in this example called
cpt_slug. Now let us loop through every CPT and add the ACF row within the repeater based on the CPT having the same title as one of the
event_title fields within that repeater row.
We need something that matches (the most of obvious of which is the title) so that we can know when to skip to the next CPT. Once we are done migrating one repeater row matched with its accompanying CPT, we move onto the next repeater row, until all repeater rows have been processed.
To initiate this migration, you would simply have to add this function, and save any post within WordPress.
Of course, to improve upon this, there are more resilient ways to accomplish the challenge.