This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

datepicker year range for dropdown

Home Forums Product Support Forums Ajax Search Pro for WordPress Support datepicker year range for dropdown

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #34152
    zisis19zisis19
    Participant

    Hello,
    we encounter an “issue” with the datepicker dropdown that is being used as one of the filter criteria. Apparently the datepicker follows the default rules and shows + – 10 years from the current year. However, we need to show posts that are older than this (the date is being defined through a custom field, it is not the publication date). So, we need at least + – 20 years or more from the current year for the dropdown so that the user can select the very old results.
    I searched the options thoroughly but couldn’t find any such setting. Is there a customization, a php function or a script function we can write somewhere in the child theme to enable the broader range for the datepicker dropdown?
    Many thanks in advance

    #34162
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    Interesting question. I googled a bit around the datepicker script, and there is actually a way to extend the range. I constructed a custom script, which should hopefully resolve this – by adding +-100 years to the range on the page load.

    add_action('wp_footer', 'wp_footer_datepicker_range_fix', 9999);
    function wp_footer_datepicker_range_fix() {
    	?>
    	<script>
    	(function($){
    		setTimeout(function(){
    			$('.asp_datepicker.hasDatepicker').datepicker('option', 'yearRange', '-100:+100')
    		}, 500);
    	})(jQuery);
    	</script>
    	<?php
    }

    Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    #34163
    zisis19zisis19
    Participant

    Hi Ernest,
    thank you for your reply. I just used the code in my functions.php but it didn’t do the trick :/. I can see the code with the debugger in the footer, but the range is still the same..

    #34165
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Can you please send a link to the page where I can check this? Thank you!

    #34167
    zisis19zisis19
    Participant

    Sure
    WEB url: https://www.kgrp.de/

    also an admin account. You can find the datepicker when you login through the form on the top right > Ihr Konto and then the “Rundschreiben” Tab.

    User: kgrp-ajaxsearchpro Pass: Ojq5$nL2Vg@Pc2C*6L

    #34168
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Thank you!

    Try this variation instead, it should work:

    add_action('wp_footer', 'wp_footer_datepicker_range_fix', 9999);
    function wp_footer_datepicker_range_fix() {
    	?>
    	<script>
    	(function($){
    		setTimeout(function(){
    			$('.asp_w .hasDatepicker').datepicker('option', 'yearRange', '-100:+100')
    		}, 500);
    	})(jQuery);
    	</script>
    	<?php
    }
    #34170
    zisis19zisis19
    Participant

    Uhlala, it worked :). Thank youuu.

    #34171
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

    #34172
    zisis19zisis19
    Participant

    yep you can close it. I found the datepicker manual as well and now that I know the correct selector, I can play with it. Thanks

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘datepicker year range for dropdown’ is closed to new replies.