Hi,
As discussed in this tread: https://toolset.com/forums/topic/custom-title-from-post-form/ I am now able to autogenerate a post title when submitting a form.
This is the code used:
***********
function my_save_data_action5($post_id, $form_data){
// Change your CRED Form "ID" accordingly below
if ($form_data['id']==1577){
//Declare the content of your variables, change "your_custom_field_slug" accordingly
$custom_title = 'Rapportnummer ' . $post_id;
//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', 'my_save_data_action5’,10,2);
// END autotittel5
****************
I have 30 post forms on this site, and I am wondering if it is possible to make this work on several forms (spesific forms), rather than duplicating the code over and over again. (With tweeks to accomodate the spesific post form id)
Maybe something like this?:
******
function my_save_data_action($post_id, $form_data){
// Change your CRED Form "ID" accordingly below
if ($form_data['id']==1577,1578,1579,1580){
//Declare the content of your variables, change "your_custom_field_slug" accordingly
$custom_title = 'Rapportnummer ' . $post_id;
//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', 'my_save_data_action’,10,2);
// END autotittel5