Customize Toolset Form’s auto draft post title

Author: 

Brad Tipper


Description: 




Kind:

PHP, Toolset


PHP:

function cred_nice_log_item_titles($post_id, $form_data) {
// Log Item Form
if ( $form_data["id"]==302 ) {
$date_format = get_option('date_format');
$date = get_post_meta($post_id, 'wpcf-date-checked', true);
$formatted_date = date($date_format,$date);
$post_date = $_POST['wpcf-date-checked']['datetime'] . ' 00:00:00';
//Build the title & slug
$title = "Log Item". " ".$formatted_date." ".$_POST["wpcf-checked-by"];
$slug = sanitize_title($title);
// Update the post into the database
$my_post = array(
'ID' => $post_id,
'post_title' => $title,
'post_name' => $slug,
'post_date' => $post_date,
// 'post_date_gmt' => get_gmt_from_date( $date )
);
wp_update_post( $my_post );
}
}
add_action("cred_save_data","cred_nice_log_item_titles",10,2);


URL: