Hi, this is a continuation of https://toolset.com/forums/topic/cred-save-data-action/
Apologies for the delay.
I made the suggested change in priority, but getting the same response. I've included the first action ("account name") which works. The problem is "session name", the second action, which I'm getting post titles such as "1585267200"
Thanks in advances.
function my_save_data_action($post_id, $form_data){
// Change your CRED Form "ID" accordingly below
if ($form_data['id']==118){
//Declare the content of your variables, change "your_custom_field_slug" accordingly
$custom_title = get_post_meta( $post_id, 'wpcf-account-name', true );
//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_action2',10,2);
function my_session_save_action($post_id, $form_data){
// Change your CRED Form "ID" accordingly below
if ($form_data['id']==28){
//Declare the content of your variables, change "your_custom_field_slug" accordingly
$first = get_post_meta( $post_id, 'wpcf-client-first-name', true );
$last = get_post_meta( $post_id, 'wpcf-client-last-name', true );
$date = get_post_meta( $post_id, 'wpcf-session-date', true );
$custom_title = $date.' '.$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', 'my_session_save_action',10,2);
Hello and thank you for contacting the Toolset support.
Toolset stores the date field to database as a timestamp, that's why your field is having numbers. You will need to format it into a human-readable date with the PHP date function, like date("F j Y", $date).
Check this post which is a little similar to your case https://toolset.com/forums/topic/append-date-field-to-title/
hidden link
I hope this helps. Let me know if you still need assistance.
Hello, thank you for your help. However I am still getting the same result.Notice I did add the date format as in the example you referred me to.
My functions look as such:
function my_save_data_action($post_id, $form_data){
// Change your CRED Form "ID" accordingly below
if ($form_data['id']==118){
//Declare the content of your variables, change "your_custom_field_slug" accordingly
$custom_title = get_post_meta( $post_id, 'wpcf-account-name', true );
//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_action2',10,2);
function my_session_save_action($post_id, $form_data){
// Change your CRED Form "ID" accordingly below
if ($form_data['id']==28){
//Declare the content of your variables, change "your_custom_field_slug" accordingly
$first = get_post_meta( $post_id, 'wpcf-client-first-name', true );
$last = get_post_meta( $post_id, 'wpcf-client-last-name', true );
$date = get_post_meta( $post_id, 'wpcf-session-date', true );
$formated_date = date("F j Y", ($date));
$custom_title = $date.' '.$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', 'my_session_save_action',10,2);
It seems that you are not using the formatted date online 32. Use this:
$custom_title = $formated_date.' '.$last.' '.$first;
Instead of
$custom_title = $date.' '.$last.' '.$first;
Let me know if it works.