Home Forums Front-end Issues acf_load_field for Date type


acf_load_field for Date type

  • I want populate value in a front-end form

    For a dropdown your example is :

    function my_acf_load_field( $field ){
        $field['choices'] = array('custom' => 'My Custom Choice');
        return $field;
    add_filter('acf_load_field', 'my_acf_load_field');

    I’have found for a field text or textarea :

    function my_acf_load_field( $field ){
        $field['default_value'] = "2010-02-21 00:00:00";
        return $field;
    add_filter('acf_load_field', 'my_acf_load_field');

    But I don’t found for Date type (datepicker)

    Can you help me please.

  • for populate a filled out value at frontend you can do something like that:

    *  Create PHP DateTime object from Date Piker Value
    *  this example expects the value to be saved in the format: yymmdd (JS) = Ymd (PHP)
    $date = DateTime::createFromFormat('Ymd', get_field('date_picker'));
    echo $date->format('d-m-Y');

    official Datepicker Documentation

    or did you wish to prefill a datepicker field?

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

The topic ‘acf_load_field for Date type’ is closed to new replies.