[Resolved] Post expiration date in form doesn’t work anymore
This thread is resolved. Here is a description of the problem and solution.
Problem:
Post expiration date in form doesn't work anymore -set post expiration time using generic custom date field
Solution:
Toolset forms saves the post expiration time to postmeta table with the key "_cred_post_expiration_time". To override the value of post expiration time based on the custom date field value, you will require to use the Toolset form's hook "cred_submit_complete".
Now it doesn't work anymore for some reason. Now what happens is: the date is changed to the default (what is defined in form settings) expiration date after saving. If there is no default expiration time set, the expiration date is set to current date.
Can you please share on what page you added the form and share admin access details. Please share where you added the code I shared.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
This 60 days would be the expiration time if user doesn't fill the date in date field. I did try this also without this "default" expiration time. Didnt' work that way either.
However - I see weird datepicker when I click on calendar icon. Can you please disable this or tell me how can I display the calendar normally?
=> hidden link
I've adjusted the code snipped code as given under:
add_action('cred_submit_complete', 'func_submit_complete',10,2);
function func_submit_complete($post_id, $form_data){
// if a specific form
if ($form_data['id']==7654 or $form_data['id']==7655){
if (isset($_POST['expiration-date']['datepicker'])){
update_post_meta($post_id, '_cred_post_expiration_time', $_POST['expiration-date']['timestamp']);
}else{
$current_plus_60_days = strtotime("+60 days");
update_post_meta($post_id, '_cred_post_expiration_time',$current_plus_60_days);
}
}
}
I've added the post with title "ts-test-9" and selected the exipiration date 9th June and once I create the post using form when I check on the backend, it shows the 9th June as expiration date.