Tell us what you are trying to do?
As a user is created it simultaneously creates a CPT record.
What is the best way to do this and is is there an example.
The best way to do this is to create a post with custom code using the Forms API. Here's an example: https://toolset.com/forums/topic/auto-create-custom-post-after-new-user-submission/#post-492026
Hi Christian
I have used this code, it saves the new cpt but the title is blank. I want to save the user first and last name in the title. Just tested it with the first name but not working.
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
if ($form_data['id']==23681)
{
$my_post = array(
'post_title' => $_POST['user_firstname'],
'post_content' => '',
'post_status' => 'publish',
'post_author' => $user_ID,
'post_type' => 'cp-provider'
);
wp_insert_post( $my_post );
}
}
Try first_name and last_name:
'post_title' => $_POST['first_name'] . ' ' . $_POST['last_name'],
great.
Also
I have a field in the CPT i want to populate
'cp-mem-id' => $post_id, but it is not populating the cpt field
$my_post = array(
'post_title' => $_POST['first_name'] . ' ' . $_POST['last_name'],
'cp-mem-id' => $post_id,
'post_content' => 'xx',
'post_status' => 'publish',
'post_author' => $user_ID,
'post_type' => 'cp-provider'
);
If you want to set custom field values, you need a meta_input array, and if cp-mem-id is a Types field, you must use the wpcf- prefix.
$my_post = array(
'post_title' => $_POST['first_name'] . ' ' . $_POST['last_name'],
'meta_input' => array(
'wpcf-cp-mem-id' => $post_id
),
'post_content' => 'xx',
'post_status' => 'publish',
'post_author' => $user_ID,
'post_type' => 'cp-provider'
);
Trying to reference the user first name and pass it to cpt
'meta_input' => array(
'wpcf-cp-mem-id' => $post_id,
'wpcf-cp-First-Name' => $_POST['last_name']
),
First name or last name? Your code says last_name.
Then you should change it to first_name:
'meta_input' => array(
'wpcf-cp-mem-id' => $post_id,
'wpcf-cp-First-Name' => $_POST['first_name']
),
Just need to have the field all in lowercase and then it works.
Thank you for all your help.