Support

Account

Home Forums Backend Issues (wp-admin) Get years below 1917 to show on date field select box

Solved

Get years below 1917 to show on date field select box

  • I’m using date field to select date for an historical event. Right now field only allows me to select down to year 1917 (which I’m guessing is 2017 – 100).

    How can I change that range? I don’t see any options in the field configuration panel.

  • This is probably something to do with the datepicker. You need to see this page about adding custom javascript to acf https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/, see the section on date and time picker args and this documentation on the datepicker that will tell you what the arguments are https://api.jqueryui.com/datepicker/

  • Use the appropriate hook

    functions.php

    
    function my_admin_enqueue_scripts() {
    
    	wp_enqueue_script( 'date-picker-js', get_template_directory_uri() . '/js/custom_date_picker.js', array(), '1.0.0', true );
    
    }
    
    add_action('admin_enqueue_scripts', 'my_admin_enqueue_scripts');
    

    custom_date_picker.js

    
    // function to merge two Javavascipt objects IE compatible, from prototype.js http://prototypejs.org/doc/latest/language/Object/extend/
    function extend(destination, source) {
    	for (var property in source)
    		destination[property] = source[property];
    	return destination;
    }
    
    // Acf hook -> Hooks -> Filters -> date_picker_args
    // see https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/
    acf.add_filter('date_picker_args', function( args, $field ){
    	
    	// do something to args
    	
    	var custom_args = {
    	  yearRange:			"-200:+100", // value to change
    	};
    	
    	args = extend(args, custom_args)
    	
    	// return
    	return args;
    			
    });
    
  • I have the same need of saving historic dates (down to 17th century).

    I used the script that @aminta wrote and it allows the user to select the historic date fine, and the date is saved correctly to the DB (Jan 1, 1700 is ‘17000101’ on DB)

    But when I edit the post (on backend) I get the default date of today instead of the saved date of Jan 1, 1700…

    How can I fix this?

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

You must be logged in to reply to this topic.