I'm trying to update the post title when a form is submitted with the value of a custom date field. Here's my hook so far:-
add_action('cred_submit_complete', 'after_save_data_form_485',10,2);
function after_save_data_form_485($post_id, $form_data) {
if ($form_data['id']==485) {
//get custom date field
$custom_date = get_post_meta($post_id, 'wpcf-custom-date', true);
// create array
$new_title = array(
'ID' => $post_id,
'post_title' => $custom_date,
);
// Update post title
wp_update_post( $new_title );
}
}
As it stands, the updated post title becomes the timestamp. Is it possible to convert this into a readable format, e.g. 20 Aug 2019 (in a types field this would be 'd M Y' format)?
Hello. Thank you for contacting the Toolset support.
Actually - Types date field value saved as Unix Timestamp. So if you want to display the formated date you need to convert the Unix Timestamp to formated date.
Could you please try to use folloowing code and try to resolve your issue.
add_action('cred_submit_complete', 'after_save_data_form_485',10,2);
function after_save_data_form_485($post_id, $form_data) {
if ($form_data['id']==485) {
//get custom date field
$custom_date = get_post_meta($post_id, 'wpcf-custom-date', true);
$custom_date = date("d M Y",$custom_date);
// create array
$new_title = array(
'ID' => $post_id,
'post_title' => $custom_date,
);
// Update post title
wp_update_post( $new_title );
}
}