Sorry, I didn't receive any screenshot but I have an example that should help. Let's assume there is a custom post type Books (slug is "book") that includes an RFG Chapters (slug is "chapters). In the Chapters RFG there is a custom field Chapter Number (slug in wp-admin is "chapter-number", meta key in database is "wpcf-chapter-number"). There is a Form that creates new Book posts. When this Form is submitted, it should automatically generate 3 Chapter RFGs. It should automatically assign the correct sort order to the RFGs, and it should set the Chapter Number custom field to be 1, 2, and 3 respectively. See the screenshot here showing the new Book post and 3 automatically generated Chapters in wp-admin.
This code was used to generate the 3 Chapter RFGs shown here, in the proper order, with the custom field values defined:
// https://toolset.com/forums/topic/predefined-repeatable-group/
// Form 18 creates new book posts.
// This code automatically generates 3 chapter rfgs inside the new book,
// assigns the correct sort order, and sets chapter number custom field values in each RFG
// --
add_action('cred_submit_complete', 'tssupp_auto_generate_rfgs',10,2);
function tssupp_auto_generate_rfgs($post_id, $form_data)
{
// trigger this code when Form 18 is submitted
if ($form_data['id']==18)
{
// create chapter 1 rfg
$chap1_args = array(
'post_title' => 'Chapter 1',
'post_content' => '',
'post_type' => 'chapters',
'post_status' => 'publish',
);
$chap1 = wp_insert_post($chap1_args);
// add custom fields and set sort order
update_post_meta($chap1, 'wpcf-chapter-number', 1);
update_post_meta($chap1, 'toolset-post-sortorder', 1);
// assign this RFG row to the new Book
toolset_connect_posts( 'chapters', $post_id, $chap1);
// create chapter 2 rfg
$chap2_args = array(
'post_title' => 'Chapter 2',
'post_content' => '',
'post_type' => 'chapters',
'post_status' => 'publish',
);
$chap2 = wp_insert_post($chap2_args);
// add custom fields and set sort order
update_post_meta($chap2, 'wpcf-chapter-number', 2);
update_post_meta($chap2, 'toolset-post-sortorder', 2);
// assign this RFG row to the new Book
toolset_connect_posts( 'chapters', $post_id, $chap2);
// create chapter 3 rfg
$chap3_args = array(
'post_title' => 'Chapter 3',
'post_content' => '',
'post_type' => 'chapters',
'post_status' => 'publish',
);
$chap3 = wp_insert_post($chap3_args);
// add custom fields and set sort order
update_post_meta($chap3, 'wpcf-chapter-number', 3);
update_post_meta($chap3, 'toolset-post-sortorder', 3);
// assign this RFG row to the new Book
toolset_connect_posts( 'chapters', $post_id, $chap3);
}
}
You now have examples showing how to create multiple RFGs, assign the proper sort order, and set custom field values in each RFG. Let me know if you need something else.