Set default date in datepicker of an advanced custom field

I am using Advanced Custom Fields in my WordPress project. In it I have added 2 datepickers as custom fields for pages.

Now the main problem is whenever I add a new page both datepickers by default show up empty, but I want to set the current date of the server as a default, that is whenever I add a new page both the date pickers should have the current date of the server by default in it.

Read More

In advance thanks for the help.

Related posts

2 comments

  1. It depends on the datepicker plugin you are using. Mostly all datepickers will have a default value you can play with. Usualy it is set within the input text type that hosts the datepicker.

    <input type="text" class="datepicker" default-value="2013/07/25">
    

    And in wordpress’ php you can do :

    <input type="text" class="datepicker" default-value="<?php echo date("Y/m/d"); ?>">
    
  2. Adding a default value to an ACF date picker can be achieved by using a filter:

    // Adjust startdate default value
    add_filter('acf/load_field/name=startdate', function ($field) {
        $field['default_value'] = date('Ymd');
        return $field;
    });
    

    Replace startdate with any field name you want to apply this filter to.

    This filter goes into your theme’s (or child-theme’s) functions.php or into a template file if it makes sense for you.

    Source: https://support.advancedcustomfields.com/forums/topic/date-picker-prefilled-to-today/

Comments are closed.