Tell us what you are trying to do?
I try to change the following code in a way, that the expiration date is not based on the future publication date like in the example - instead it should be based on the timestamp of a custom datepicker field.
What I found in the documentation:
I have a Form that create posts. I would like to schedule those posts for future publication, and I would like to set a custom post expiration date based on the future publication date.
add_action('cred_save_data', 'set_expiration_date',10,2);
function set_expiration_date($post_id, $form_data)
{
$forms = array( 35927 );
if (in_array($form_data['id'], $forms)) {
// update post publish date based on generic date field
$timestamp = $_POST['wpcf-ablauftermin']['datepicker'];
$date = date('Y-m-d H:i:s', $timestamp);
if(isset($timestamp)){
$args = array(
'ID' => $post_id,
);
wp_update_post( $args );
// update post expiration date based on generic date field and time calculation
$expiry_timestamp = $timestamp + ( 6 * 60 * 60 );
update_post_meta($post_id, '_cred_post_expiration_time', $expiry_timestamp );
}
}
}
My changed code:
add_action('cred_save_data', 'set_expiration_date',10,2);
function set_expiration_date($post_id, $form_data)
{
$forms = array( 35927 );
if (in_array($form_data['id'], $forms)) {
// try to load custom datepicker field
$lastday = $_POST['wpcf-ablauftermin']['datepicker'];
if(isset($lastday)){
$args = array(
'ID' => $post_id,
);
// update post expiration date based on generic date field and time calculation
$expiry_timestamp = $lastday + ( 6 * 60 * 60 );
update_post_meta($post_id, '_cred_post_expiration_time', $expiry_timestamp );
}
}
}
Did I made any major mistakes in the code?
Is there any documentation that you are following?
https://toolset.com/forums/topic/post-expiry-for-post-types-not-using-cred-post-forms/
Is there a similar example that we can see?
In the documentation
What is the link to your site?
hidden link