Home Forums Backend Issues (wp-admin) Default value for datepicker


Default value for datepicker

    • psyfire

    • February 9, 2021 at 12:50 pm


    I am trying to get a default value for datepicker, basically if field abc has no value, then it should have value xyz. If the field has value, then the value will be displayed. I have tried it with several solutions but I am no expert:

    add_filter('acf/load_field/name=date_of_birth', function ($field) {
        $field['default_value'] = date('d.m.Y');
        return $field;


    $goempty = '---';
    $defaultdateofbirth = get_field('date_of_birth');
    if (empty($defaultdateofbirth)) {
    update_field('date_of_birth', '---');
    } else {
    update_field('date_of_birth', $goempty);

    The second one adds the today’s date and overwrites everything else.

    Can someone help me figure out a solution for that? Thanks!!

    • psyfire

    • February 12, 2021 at 8:47 pm

    Has really no one an idea how to solcve this? 🙁

  • If you want to set the default value of a date field when loading a field it must be in the same format that ACF stores in the DB

    add_filter('acf/load_field/name=date_of_birth', function ($field) {
        $field['default_value'] = date('Ymd');
        return $field;
    • NickDA

    • June 2, 2021 at 5:54 am

    I can now confirm John’s solution above is perfect and does the trick like a charm !

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.