Christian Cox helped me with this function below almost 2 years ago.
Im using it now with a different cred form to rename the post created from the first and last name in the submitted data.
The form writes all the data to the post correctly however if i goto to view it. I get a 404 Ive refreshed permalinks- When i remove the function the form saves as a draft with a random name and that views just fine. HAs something changed in the last 2 years that would cause this or might it be something else. Not sure what to do to trouble shoot
function sf_save_data_action_juried($post_id, $form_data){
// Change your CRED Form "ID" accordingly below
if ($form_data['id']==15806){
//Declare the content of your variables, change "your_custom_field_slug" accordingly
$first = get_post_meta( $post_id, 'wpcf-ca-first-name', true );
$last = get_post_meta( $post_id, 'wpcf-ca-last-name', true );
$custom_title = $last.' '.$first;
//collect data and define new title
$my_post = array(
'ID' => $post_id,
'post_title' => $custom_title,
'post_name' => $custom_title,
);
// Update the post into the database
wp_update_post( $my_post );
}
}
add_action('cred_save_data', 'sf_save_data_action_juried',10,2);
// use this hook if saving from back end save_post()