Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › datepicker year range for dropdown
- This topic has 8 replies, 2 voices, and was last updated 4 years, 10 months ago by
zisis19.
-
AuthorPosts
-
August 4, 2021 at 8:27 am #34152
zisis19
ParticipantHello,
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 advanceAugust 4, 2021 at 11:33 am #34162Ernest Marcinko
KeymasterHi,
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.
August 4, 2021 at 11:37 am #34163zisis19
ParticipantHi 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..August 4, 2021 at 11:43 am #34165Ernest Marcinko
KeymasterCan you please send a link to the page where I can check this? Thank you!
August 4, 2021 at 12:34 pm #34167zisis19
ParticipantSure
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
August 4, 2021 at 12:40 pm #34168Ernest Marcinko
KeymasterThank 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 }August 4, 2021 at 12:50 pm #34170zisis19
ParticipantUhlala, it worked :). Thank youuu.
August 4, 2021 at 12:50 pm #34171Ernest Marcinko
KeymasterYou cannot access this content.
August 4, 2021 at 1:08 pm #34172zisis19
Participantyep 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
-
AuthorPosts
- The topic ‘datepicker year range for dropdown’ is closed to new replies.