Problem: I am using a form created in Gravity Forms to create new posts. I would like to capture a date using a GF date field and store it in a Types date field, but the formats are incompatible.
Solution: Add some custom code to functions.php or to a new custom code snippet in Toolset > Settings > Custom code:
// convert gravity forms date field to types date format add_filter("gform_post_data", 'set_my_gravity_date', 10, 3); function set_my_gravity_date($post_data, $form, $entry ) { $form_id = 12345; $types_field_slug = 'types-field-slug'; $gf_field_id = 67890; // you should not edit below this line //check if this is the right form if ( isset($form['id']) && $form['id'] == $form_id ) { // add unix timestamp for date field in meta_input $post_data['meta_input']['wpcf-' . $types_field_slug] = strtotime(rgar($entry, $gf_field_id)); } return $post_data; }
You should change 12345 to match the Gravity Form ID. You can find that in the form editor. You should change types-field-slug to match the slug of your custom date field. You can find that by editing the custom field in wp-admin. Then you should replace 67890 with the numeric ID of the Gravity Forms date field. You can find that in the GF form editor when you hover over the field. Then use the Types field shortcode to display the field with whatever format you want on the frontend of the site.
Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/
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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
Este tema contiene 2 respuestas, tiene 2 mensajes.
Última actualización por hace 5 años, 9 meses.
Asistido por: Christian Cox.