Home Forums Front-end Issues Save ACF field with actual now date and time


Save ACF field with actual now date and time

  • I’m building a check-in form that showed in front-end. I’m using ACF date and time picker to get actual time when the user clicks the submit button.

    The problem is: ACF date and time picker, well, is a picker.

    What I want is the user no need to pick the actual date and time. But when users submit the form, the actual time (when submitting) is saved into ACF date-time field.

    How to fill the date and time field with the current date and time when the user clicks the submit button?

    Thank you.

    add_action('acf/save_post', 'set_submit_time');
    set_submit_time($post_id) {
      // field key of date/time field
      // use field key
      update_field('field_XXXXXXX', data(Y-m-d H:i:s'), $post_id);
  • @hube2 you are really a savior. Thanks for helping.

    There’s a bit typo, but really, you save the day. So for anyone else out there, here’s the functional code:

    # Save the actual time when user click submit
    add_action( 'acf/save_post', 'set_submit_time' );
    function set_submit_time($post_id) {
    	update_field('field_XXXXXX', date('Y-m-d H:i:s'), $post_id);

    You can add within functions.php or your singlepage.php before the acf_form_head();

    Oh and also, if you need to get local time, change the date to this:

    update_field('field_XXXXXX', date('Y-m-d H:i:s', current_time( 'timestamp', 0 )), $post_id);

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.