Problem: I would like to set the publish date and time of a post within the CRED Form used to create that post.
Solution: There's no post publish date field built into CRED, so this will require some custom code and a generic field. Add a generic date field to your CRED form, then add this code to functions.php:
add_action('cred_save_data', 'set_post_date_to', 100, 3); function set_post_date_to($post_id, $form_data) { if( $form_data['id'] == 12345 ) { $newDate = $_POST['set-new-date']['datetime'] . ' 00:00:00'; $my_post = array( 'ID' => $post_id, 'post_date' => $newDate, 'post_date_gmt' => $newDate, 'post_status' => 'future' ); // Update the post into the database wp_update_post( $my_post ); } }
- Change the form id 12345 to match your form.
- Change 'set-new-date' to match the slug of your generic date field
Relevant Documentation:
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
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 4 respuestas, tiene 2 mensajes.
Última actualización por hace 7 años, 2 meses.
Asistido por: Christian Cox.