Skip Navigation

[Resolved] Split: Create a new CTP post when a user is created with user-registration a CRED form – add on questions

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 6 replies, has 2 voices.

Last updated by Minesh 4 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2710748

Works great
I also wanted to populate custom fields in the post from custom fields in the user form,
I followed the tickets
https://toolset.com/forums/topic/create-new-post-upon-adding-new-user/
https://pastebin.com/Y1pWeJnP
I tried for a long time without success
I would appreciate a solution
I am attaching pictures of the custom fields
Thank you
Younes

#2710750

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - I need to check what's going wrong with your setup but before that I need to know your site's workflow and how the hook you created works and what custom fields you want to store and whats working and whats not working.

Can you please share all those required details with problem URL and admin 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.

#2710753

Minesh
Supporter

Languages: English (English )

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

But at what course of the action you want the custom field - korot - of the post, to receive the data from the custom field -korothaiim- of the user form?

Do you mean you have user form and you create user profile post when you submit the user form and you have custom field korot on user form and you want to save custom field korot (that is on user form) and copy the content of this field to user custom field korothaiim?

If you can explain whole scenario and share what form you are using that would help me to guide you in the right direction.

#2710755

The user fills out a user form and there is a custom field name (File)'korothaiim'!
After saving the form, 'post_type' => 'Programmer' is created automatically
The post has a custom field - (File) 'korot''
And I need the file that the user uploaded in the user form to be saved in the post
Thank you very much for all the help

#2710894

Minesh
Supporter

Languages: English (English )

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

Can you please share what is the hook and what code you are using to create "programmer" post after you submit the user form?

Can you please share the code you are using.

#2710895

I use the code you sent me on the card - https://toolset.com/forums/topic/create-a-new-ctp-post-when-a-user-is-created-with-user-registration-a-cred-form-2/

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data) {

if ($form_data['id']==21) {

// Create new entry after registration.
$my_post = array(
'post_title' => $_POST['first_name'],
'post_content' => '',
'post_status' => 'publish',
'post_author' => $post_id,
'post_type' => 'programer'
);
// Insert the post into the database
wp_insert_post( $my_post );
}
}

#2710926

Minesh
Supporter

Languages: English (English )

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

I've adjusted the code as given under:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data) {

if ($form_data['id']==21) {

$user_field_slug = "wpcf-korothaiim";   /// change if required 
$post_field_slug = 'wpcf-korot';        /// change if required


// Create new entry after registration.
$my_post = array(
'post_title' => $_POST['first_name'],
'post_content' => '',
'post_status' => 'publish',
'post_author' => $post_id,
'post_type' => 'programer'
);
// Insert the post into the database
$profile_post_id = wp_insert_post( $my_post );

       if( isset( $profile_post_id ) && $profile_post_id ) {
                 $user_field_value = get_user_meta($post_id,$user_field_slug, true); 
                 update_post_meta($profile_post_id,$post_field_slug,$user_field_value);
                          
      }




}
}

Can you please try to use the above code and try to resolve your issue.