Support

Account

Home Forums General Issues Date Picker question

Helping

Date Picker question

  • The documentation doesn’t appear to answer a couple of issues I am having.

    1. There seems to be a limit to the earliest year you can go back to – 1925. Is there a way around this?
    2. If I only have a year, rather than a full date, obviously I can’t use the date picker function BUT even if I type it in manually into the field it doesn’t seem to retain the data. Is this due to a wordpress limitation – that it only store dates in the YYYYMMDD format?

    Context: I have a site which contains biographies of people, mostly bornin ain the 1800s. For many of those people I only have a year of birth (or approximate year of birth) and not a specific date. Can I use the date picker to record/retain this data or is the only solution to use a free text field? If anyone has any ideas around this I;d love tto hear them.

    Thank you 🙂

    I’m using WordPress, Divi Theme, ACF free version.

  • The ACF Date Picker field actually uses the jQuery UI Datepicker. By default, its year range is from 1925 up to the current year.

    You can write custom JS to override the yearRange option:

    add_action('acf/input/admin_footer', function() {
        ?>
        <script type="text/javascript">
        (function($) {
            if (typeof acf !== 'undefined') {
                acf.add_action('ready_field/type=date_picker', function($field){
                    $field.find('input.input').datepicker('option', {
                        yearRange: '1800:c', // 1800 from a specific year up to the current year.
                        changeMonth: true,
                        changeYear: true
                    });
                });
            }
        })(jQuery);
        </script>
        <?php
    });
    

    This way, you can easily select years like 1800 or even earlier.

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

You must be logged in to reply to this topic.