I have two date fields set up- "from" and "to".
When creating a post with a CRED form, I want to copy the value entered in the "from" date field and save it in the "to" field.
I've tried the following (ignore form ID):
function cred_copy_date( $post_id, $form_data ) {
if ( $form_data["id"]==1 ) {
$post_id = get_the_ID();
$date = $_POST['wpcf-from']['timestamp'];
update_post_meta( $post_id, 'wpcf-to', $date );
}
}
add_action( "cred_save_data", "cred_copy_date", 10, 2 );
I assume I'm not using the correct part of the date object array- what should I use? The timestamp? Just $_POST['wpcf-from'] ? Something else? I've tried several options and can't seem to find one that works.
Hi David,
Thank you for waiting.
During troubleshooting, I noticed that the function that you're using is correct, except for the following line:
This line incorrectly replaces the newly entered post's ID, with the ID of the post/page, where the form is placed. As a result, the function "update_post_meta" updates the custom fields on the post/page with the form, instead of the newly added post.
Please remove that line and then check the form submission again.
regards,
Waqar