2

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.

In advance thanks for the help.

2 Answers 2

0

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"); ?>">
3

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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.