Home › Forums › ACF PRO › convert repeater field into custom post type › Reply To: convert repeater field into custom post type
I cannot think of any easy way to do this.
I would create the CPT and then I would create a function that did this that I would remove when the process is complete.
I would also set the options page auto_load argument to true and save the options page, this alone might speed up the loading of the options page. But you need ti to auto load for the conversion.
Next thing is that I would create a new text field in the repeater called “tranfered_to_post” or something like that, name does not really matter. Again, save the options page to and this will make sure the new sub field exists in all of the rows.
add_action('init', 'move_repeater_to_cpt');
function move_repeater_to_cpt() {
// set some reasonable limit on the number of posts to create
// to prevent timeout
$limit = 20;
// count of posts created
$count = 0;
if (have_rows('repeater', 'options')) {
while(have_rows('repeater', 'options')) {
the_row();
if (!empty(get_sub_field('tranfered_to_post')) {
// this row already done, move to the next one
continue;
}
// *********************************************
// create a new post base on row data
// *********************************************
// mark the row as done
update_sub_field('tranfered_to_post, 'done');
} // end while have_rows
} // end if have_rows
} // end function
then you just need to keep reloading any page on the site until all of the rows are converted. Then delete the function.
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.