Skip Navigation

[Waiting for user confirmation] Unable to connect RFG with posts

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 7 replies, has 1 voice.

Last updated by Minesh 2 days, 9 hours ago.

Assisted by: Minesh.

Author
Posts
#2817693
Screenshot 2025-07-26 at 11.36.44 am.png

Toolset version: 3.6.1
PHP: 8.3.1
WordPress: 6.7.2
Custom post: Students (slug: sutdent)
RFG: Payments (This field group connected with student)

I am using code to create student and then RFG and connect it with students.
$student_id = wp_insert_post( [
'post_type' => 'student',
'post_title' => $data['first_name'] . ' ' . $data['last_name'],
'post_status' => 'publish',
] );
$payment_entry_id = wp_insert_attachment([
'post_type' => 'payments',
'post_status' => 'publish',
'post_title' => $reg_id
]);
$connect = toolset_connect_posts('student-payments', $student_id,$payment_entry_id,);
but $connect restults [success = false, message = The element has a wrong type or a domain for this relationship]

Please include sohaib@woof.com.au as CC in this ticket.

Thanks
sohaib@woof.com.au

#2817878

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I review the code you shared and I see that you use the following line of code:

'post_title' => $reg_id

But I do not see the reference of $reg_id variable in your code.

I do not have any way to add the additional email to which I can CC the message.

#2818025

$reg_id are a variable, contains unique ID which can be used for Post Title.

$reg_id = strtoupper( uniqid( 'REG'.$student_id ) );

#2818061

Minesh
Supporter

Languages: English (English )

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

Well - I need to check where the issue is and why the RFG entry not get connected with post.

Can you please share problem URL and admin access details and at what course of action you want to connect the RFG and what RFG items to what post. Please share all those required 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.

#2818382

Minesh
Supporter

Languages: English (English )

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

Well - what card details I can use to make payment and that should lead me to next step?

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

#2819022

Minesh
Supporter

Languages: English (English )

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

Can you please check now:

I've adjusted the code you added to your custom plugin as given under:
Code reference: plugins/jj-users-management/includes/class-jj-users-management-rest.php

public function jj_create_student_from_payment($data){
        if (
            empty( $data['first_name'] ) ||
            empty( $data['last_name'] ) ||
            empty( $data['email'] ) ||
            empty( $data['trial_id'] )
        ) {
            return;
        }

        $student_id = wp_insert_post( [
            'post_type'   => 'student',
            'post_title'  => $data['first_name'] . ' ' . $data['last_name'],
            'post_status' => 'publish',
        ] );

        if ( is_wp_error( $student_id ) ) {
            error_log( 'Failed to create student: ' . $student_id->get_error_message() );
            return;
        }

        update_post_meta( $student_id, 'wpcf-first-name', $data['first_name'] );
        update_post_meta( $student_id, 'wpcf-last-name', $data['last_name'] );
        update_post_meta( $student_id, 'wpcf-email', $data['email'] );
        update_post_meta( $student_id, 'wpcf-trial-id', $data['trial_id'] );

        $reg_id = strtoupper( uniqid( 'REG'.$student_id ) );
        update_post_meta( $student_id, 'wpcf-student-id', $reg_id );


        $payment_entry_id = wp_insert_post([
            'post_type'   => 'payments',
            'post_status' => 'publish',
            'post_title'  => $reg_id
        ]);

        if (!is_wp_error($payment_entry_id)) {
            update_post_meta($payment_entry_id, 'wpcf-payment-details', $data['payment_id']);
            update_post_meta($payment_entry_id, 'wpcf-amount', '200'); // hardcoded for now
            update_post_meta($payment_entry_id, 'wpcf-payment-date', date('Y-m-d'));

            $connect = toolset_connect_posts('payments', $student_id,$payment_entry_id);


            //$name = 'sohaib';

        } else {
            error_log('Failed to create payment repeatable entry: ' . $payment_entry_id->get_error_message());
        }

    }

Can you please confirm it works as expected.

#2819306
Screenshot 2025-08-07 at 12.28.42 pm.png

Hey,
I tried your code but it did not connected the RFG with student post.
$connect = toolset_connect_posts('payments', $student_id,$payment_entry_id);

$connect returns "The element has a wrong type or a domain for this relationship." as can be seen in attachment.

#2819319

Minesh
Supporter

Languages: English (English )

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

I do not know why its showing you error but I can see that when I make the payment I can see the repeating field group item is attached to post.

See the following post:
- hidden link

I can see that repeating field group item there with all the repeating field group fields. Maybe you can return true or success message after the following line of code:

$connect = toolset_connect_posts('payments', $student_id,$payment_entry_id);