Skip Navigation

[Resolved] Copy date from one date field to another when saving post

This support ticket is created 3 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 3 years, 6 months ago.

Assigned support staff: Waqar.


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.



Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi David,

Thank you for waiting.

During troubleshooting, I noticed that the function that you're using is correct, except for the following line:

$post_id = get_the_ID();

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.