When a user submits a front-end CRED form I want the value they select here: In a field with a slug of "opportunity-removal-date" to get populated here: cred-post-expiration, but I haven't been able to get it to work using this code snippet.
I know these are Toolset based fields and not ACF but I was hoping something similar would work.
add_action('admin_footer', function () {
?>
<script type="text/javascript">
$('#cred-post-expiration').on('keyup', e => {
$('#opportunity-removal-date').val(parseFloat(e.target.value));
})
</script>
<?php
});
Again, rather than iterating on an existing solution, let's first clarify exactly what it is that you want to do.
Your users will be updating/creating posts via front-end forms, rather than in the back-end post edit screens?
And you want to include a field "opportunity-removal-date" in the form, and have this date automatically copied across to the hidden cred post expiration field, so that the post will automatically expire at that time?
Yes that is correct! I want to include a field "opportunity-removal-date" in the form, and have this date automatically copied across to the hidden cred post expiration field, so that the post will automatically expire at that time.
Post expiration time is saved with the meta key namely "_cred_post_expiration_time" to the postmeta database table that holds the date field value as Unix Timestamp. That is why we will require to save the timestamp with the post meta key "_cred_post_expiration_time".
add_action('cred_save_data', 'func_set_custom_post_expiration_date',10,2);
function func_set_custom_post_expiration_date($post_id, $form_data){
// if a specific form
if ($form_data['id']==99999){
$expiry_date = $_POST['date-field-slug']['timestamp'];
update_post_meta($post_id, '_cred_post_expiration_time', $expiry_date );
}
}
Where:
- Replace 99999 with your original form ID
- Replace "date-field-slug" with your original custom date field slug.
I will require problem URL where you added the form as well as admin access details.
*** 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.