Support

Account

Home Forums Backend Issues (wp-admin) Date Picker – Prefilled To Today

Solving

Date Picker – Prefilled To Today

  • Can we have an option in ACF Pro that when the date picker field is being used that the default field can be today’s date. This is because I’m running into an issue where I have to select the date twice. Once I see the date filled in the input, I have an easier time. This would save me some unnecessary clicks if the Date Picker was pre-populated to today’s date

  • There is a filter that you can hook into and pre-populate a field. The documentation only shows this for Select fields, but you should be able to use “date-picker” to prepopulate all Date Fields, or you could lock it down to that specific date field if you reference the field key.

    https://www.advancedcustomfields.com/resources/acfload_value/

    The format of the datepicker is YYYYMMDD

  • Edd is correct, there are filters. You could use load value or you can set the default value using load_field. Here is some example code

    
    add_filter('acf/load_field/name=YOUR_FILED_NAME', 'my_acf_default_date');
    function my_acf_default_date($field) {
      $field['default_value'] = date('Ymd');
      return $field;
    }
    
  • I know this is old, but as a heads up, this worked perfectly. Thanks.

  • Thanks, the filter works well!
    Should the date format be changed to anything else if I use a different formatting?
    It seems to work without problems with Ymd too.

  • Its Oct, 2020 now…
    I wish to have the date set to today ONLY upon creation.
    BUT, ACF pro latest (5.9.1) seems to ignore it.
    Even when I modify the date – it will DISPLAY today date
    And will retain the original in the database (ie. not updating…)
    Here is my code:

    add_filter('acf/load_field/name=YOUR_FILED_NAME', 'my_acf_default_date');
    function my_acf_default_date($field) {
      if (isset($field['default_value']) && $field['default_value'] != "") 
         return $field; // do not change...
      $field['default_value'] = date('Ymd');
      return $field;
    }

    Any idea how to manage this behavior is highly appreciated. Thanks!

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

The topic ‘Date Picker – Prefilled To Today’ is closed to new replies.