Skip Navigation

[Resolved] Connecting RFG to parent programmatically

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by puneetS-3 5 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#1301427

I have a use case where I can't allow user to select parent in the RFG form itself, so I have to do it programmatically.
I am using cred_save_data and toolset_connect_posts to do it.

Parent ( parent post - It's a user proxy) is only for every user and there is a RFG child which can be multiple. Now I have added the add RFG from in a view where I have queried for the posts of logged in user(author) . I get it's parent ID, from there and try passing it using forms hidden field like this :

````````````
Hidden Form
Slug : parent-id
Default : [wpv-post-id]

`````````````

The code that I am using is:

add_action('cred_save_data', 'my_save_data_action', 5, 2);

function my_save_data_action($post_id, $form_data)
{
    if ($form_data['id'] == 1515) {
		$parent_id = $_POST['wpcf-parent-id'];
		toolset_connect_posts( array('parent','child'), $parent_id, $post_id );
	}
}

Every time I submit this post I get an error saying "This website is having some technical difficulties".

#1301509

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

What if you try to add your RFG slug with the following line of code - does that help:

 toolset_connect_posts( 'repeating-field-group-slug', $parent_id, $post_id );

If no, I need problem URL where you added the form as well as access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1301525

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share access details for user who has parent role which I can use.

I have set the next reply to private which means only you and I have access to it.

#1301901

Hey Minesh,

Any update on this?

#1302599

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link

add_action('cred_save_data', 'func_set_parent_to_rfg_entry', 5, 2);
function func_set_parent_to_rfg_entry($post_id, $form_data) {
	global $current_user;
    if ($form_data['id'] == 1515) {
      
      	 $args = array(
        'post_type'      => 'parent',
        'author'         => $current_user->ID,
        'status'         => 'publish',
        'posts_per_page' => 1
        );
                       $parent_post = get_posts( $args );
                     foreach($parent_post as $parent){
                              $parent_id = $parent->ID;
                            toolset_connect_posts('child', $parent_id, $post_id );
                      }
      }
}

Now, I see once you add a child entry, it will automatically find the parent post ID based on the loggedin user ID (author) and connect that ID as a parent.

More info:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

#1303293

My issue is resolved now. Thank you very much.