Hi,
Thank you for contacting us and I'd be happy to assist.
When a repeating field group is created, a new hidden post type is also created in the backend, with the same slug as that repeating field group.
( example screenshot: hidden link )
A hidden relationship with the same slug is also created between this new post type (child) and the parent post type, for which this repeating field group was added.
Any fields which are added as part of that repeating field group, are saved as custom meta field entries against this new custom post type (child) and not the parent one.
For example, suppose you have a "Product" post type, for which you have a repeating field group called 'Product Pricing Plan' (slug: product-pricing-plan).
When you'll insert a new post in the "Product" post type, you'll also need to insert a new post in the hidden post type "product-pricing-plan", to fill the custom field values in the repeatable field group.
After that, you can connect the IDs of the newly added "Product" (parent) and "Product Pricing Plan" (child) into a relationship, using the "toolset_connect_posts" function.
( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts )
As for the custom fields, you can add or update them using the ID of that new "Product Pricing Plan" post and not the "Product" post.
Here is an example code snippet, that adds a test "Product" post and then adds a new repeating field group post "product-pricing-plan", joins them in the relationship, and updates the custom field value in the field "field-slug" in the repeatable field group.
// adding "Product" post
$product_post = array(
'post_title' => "this is a product post",
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'product'
);
$product_post_id = wp_insert_post( $product_post );
// if "Product" post has been added successfully, add a new "Product pricing plan" post (RFG)
if($product_post_id) {
$ppp_post = array(
'post_title' => "this is a product pricing plan post",
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'product-pricing-plan'
);
$ppp_post_id = wp_insert_post( $ppp_post );
// if "Product pricing plan" post has been added successfully, update custom field value and add a relationship connection
if($ppp_post_id) {
// add or update custom field value in the new "Product pricing plan" post
update_post_meta( $ppp_post_id, 'wpcf-field-slug', 'This is the value of the field');
// join "Product" and "Product pricing plan" posts through a relationship
toolset_connect_posts( 'product-pricing-plan', $product_post_id, $ppp_post_id );
}
}
You can include a similar code in your custom function that executes on form submission. Of course, you won't need the first part of the code to create the parent post, as the form will be creating the parent post for you.
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar