Hi
I'm trying to get a CRED Form to edit the last modified date of a post or custom post type to a date and time entered in the edit form. I don't know where to start in the cred_dave_data hook given the wp_update_post function will not edit the last modified date. Any help with how I can edit the last modified date from a CRED edit form would be greatly appreciated. Thank you
The following code populates the last modified date successfully in the CRED edit form:
// Populated the edit form with last modified date
//
add_filter( 'cred_filter_field_value_before_add_to_form', 'my_modified_date_function', 10, 2);
function my_modified_date_function($value, $computed_values){
if (isset($_GET['cred-edit-form']) && $_GET['cred-edit-form']==7090)
{
if($computed_values['name'] == 'my-post-modified-date'){
$pid = get_the_ID();
$time = get_the_modified_date('U', $pid);
$value['timestamp'] = $time;
}
}
return $value;
}
I've got similar functionality working with editing the Post Date using the code below which uses the wp_update_post function within the cred_save_data hook:
// Populated the edit form with current post date
//
add_filter( 'cred_filter_field_value_before_add_to_form', 'my_creation_date_function', 10, 2);
function my_creation_date_function($value, $computed_values){
if (isset($_GET['cred-edit-form']) && $_GET['cred-edit-form']==7090)
{
if($computed_values['name'] == 'my-post-creation-date'){
$pid = get_the_ID();
$time = get_the_date('U', $pid);
$value['timestamp'] = $time;
}
}
return $value;
}
// Save the new post date
//
add_action('cred_save_data', 'my_post_creation_date', 100, 3);
function my_post_creation_date($post_id, $form_data) {
if( $form_data['id'] == 7090 ) {
$mysql_time_format= "Y-m-d H:i:s";
$newDate = $_POST['my-post-creation-date']['datetime'] . ' '.$_POST['my-post-creation-date']['hour'].':'.$_POST['my-post-creation-date']['minute'].':00';
$newDate_gmt = gmdate( $mysql_time_format, ( $newDate + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
$my_post = array(
'ID' => $post_id,
'post_date' => $newDate,
'post_date_gmt' => $newDate_gmt
);
// Update the post into the database
wp_update_post( $my_post );
}
}