Hi,
i have made a post form with Formidable which have a Date field and is not compatible to Custom Fields made with Types. But i have to update my Types Field and have much Problems here so i hope anyone can help.
What i have figured out is that Toolset Types saves the date in Unix format. So with help from the formidable devlopers i have this code now. This will adjust the date format before that custom field (from formidable) is saved.
But the Problem here is furthermore not working and i get wrong values like 01/04/1970 in Types Field.
add_filter( 'frm_new_post', 'create_a_custom_field', 10, 2 );
function create_a_custom_field( $post, $args ) {
$field_id = 102; // change 25 to the id of the field to draw from
if ( isset( $_POST['item_meta'][ $field_id ] ) ) {
$field_value = sanitize_text_field( $_POST['item_meta'][ $field_id ] );
$post['post_custom']['wpcf-startzeit-produkttests'] = gmdate( 'timestamp', $field_value ); // uncomment to save a different date format and change 'custom_field_name_here'
}
return $post;
}
Please Help
Dear mirjana,
According to our Customer Support Policy, we do not provide custom codes support:
https://toolset.com/toolset-support-policy/
I am not familiar with the Formidable plugin, I assume the Formidable plugin is passing the POST parameter for date field, like this:
2009-02-15 (Y-m-d)
You can try to modify your PHP codes, for example, replace this line, from:
...
$post['post_custom']['wpcf-startzeit-produkttests'] = gmdate( 'timestamp', $field_value );
...
To:
...
$date = DateTime::createFromFormat('Y-m-d', $field_value);
$post['post_custom']['wpcf-startzeit-produkttests'] = $date->getTimestamp();
...
More help:
hidden link
Hi Yang,
sorry this is also not working (try´d just now). I think you misunderstood this, this code should adjust the date format before that custom field (from formidable) is saved.
So what i need is the right date format for wp-types custom field, so the date will be accepted from wp-types custom field wenn form is saved.
Hi Yang,
sorry its working.
I make something wrong. Sure you where right with this 🙂
Thank You