Skip Navigation

[Resolved] Create a new CTP post when a user is created with user-registration a CRED form

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 2 voices.

Last updated by Minesh 4 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2710577

I follow the card https://toolset.com/forums/topic/create-a-new-ctp-post-when-a-user-is-created-with-user-registration-a-cred-form/
And it creates a problem for me on the website that it gets stuck, I don't understand what I'm not doing well Below is my code

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($user_id, $form_data)
{
// Change your CRED Form ID
if ($form_data['id']==21){

$new_post = array(
'post_type' => 'מתכנת',
'post_status' => 'publish',
'post_title' => 111,
);
wp_insert_post($new_post);
}
}

#2710580

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I believe the post type slug should be different.

Can you try to visit the Toolset => Post Types and edit your desired post type and copy the correct slug and use the correct slug with your code: 'post_type' => 'מתכנת',

Does that helps?

#2710584
Post Type.jpg
Custom code.jpg

Tried and used slug and still same problem
Thanks in advance

#2710594

Minesh
Supporter

Languages: English (English )

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

What if you try to use the following code and try to resolve your issue:

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'    =>  "111",
  'post_content'  => '',
  'post_status'   => 'publish',
  'post_author'   => $post_id,
  'post_type' => 'programer'
);
       // Insert the post into the database
       wp_insert_post( $my_post );
}
}
#2710648

Like all your solutions it works great!!
Just another question, how do I make the title dynamic according to the first_name that the user fills in the user form
Thank you

#2710686

Minesh
Supporter

Languages: English (English )

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

Can you please try to use the following code that should help you to resolve your issue:

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 );
}
}
#2710739
User Form.jpg
Post Field.jpg

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

#2710749

Minesh
Supporter

Languages: English (English )

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

Glad to know that the original issue reported with this ticket is already resolved.

As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery.

In future - I urge you to open a new ticket with every new question you may have.

For now, I'll split the ticket with your new question and you can mark this ticket resolved.

We will continue with the following split ticket:
- https://toolset.com/forums/topic/split-create-a-new-ctp-post-when-a-user-is-created-with-user-registration-a-cred-form-add-on-questions/

Thank you for understanding.