Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Search by date range with custom fields datepicker not working
- This topic has 8 replies, 2 voices, and was last updated 8 years, 6 months ago by
Quimm.
-
AuthorPosts
-
November 27, 2017 at 1:33 pm #15640
Quimm
ParticipantIt is possible to search between two dates based on custom fields date picker? I want to select “FIRES” between two dates including the selected dates, that is very important
For example if a FIRA starts at 12/11/2017 and finish at 15/11/2017 and I select this two dates in the selectors then Fira appears in the results. Same if I select from 13 to 14 which are in the correct range.
Acf5 date_field optin not work and I can’t select Mysql DateTime, it’s not saving
Can you please check if maybe I am doing something wrong?
ThanksNovember 27, 2017 at 9:34 pm #15651Ernest Marcinko
KeymasterHi!
Thank you very much for the details. It was not your fault, there was indeed a confusion.
The ACF5 and the MySQL datetime values are the same, it should have been removed and renamed. In your case the correct choice is ACF4, which is actually the Date picker in ACF. I have changed that for you, and also noticed that the custom field logic was changed from the default ‘AND’ to ‘OR’, which was causing the main issue, as the OR logic means, that any of the chosen dates are sufficient to match – which is almost always true (and not correct): https://i.imgur.com/yv08Bat.pngIt should be okay now, however I have noticed that the day is not inclusive as it should be, this is related to the previous issue. I’ve looked up the plugin source, and made similar test fields. So choosing the day actually only includes results from starting the next day, which is not okay.
After some testing I solved the issue, but one file needs to be replaced in the plugin directory to fix it, there is no other way unfortunately.To fix it manually, please follow these instructions. If you can’t do it, feel free to leave temporary FTP access, and I will do it for you.
- 0. Make sure to have a back-up before editing the files.
- 1. Open up the wp-content\plugins\ajax-search-pro\includes\classes\etc\class-asp_helpers.php file on your server via FTP
- 2. Change it’s complete contents to this: https://goo.gl/tNecGA
- 3. Save the file
After this, the date should be inclusive to the selected date, and work correctly. I will of course include this fix in the next release of the plugin, and make sure to correct the date field names as well. Sorry about the inconvenience. Let me know if you need help with this.
November 28, 2017 at 12:37 am #15654Quimm
ParticipantHi Ernest, thank for your fast and excellent response. Now the date range works perfect.
Otherwise I have a problem with the results of the search and this maybe it can’t be done with the plugin, let me explain:
If a Fira is celebrating the days 1, 2 and 3 of February it will only appear in the results if I select Initial Date 1th February or before and 3th of February or after for End Date. The question is:
if I put in the initial date 2 of February the Fira will not appear in the results, which is correct but is not what I finally need.Maybe I’m more interested in a result where I put only one date and it shows for that date all the Fires that are in that day “active” no matter if starts or ends in that exact date. So the range is the duration of the FIRA and the filter is only one day selected by the user. This is useful for a user who wants to know which Fira is opened today for example or any day in the future or in the past.
I don’t know if I explain the problem… Can you help with this Ernest or it goes out from the support of the plugin?
Thanks a lot!
QuimNovember 28, 2017 at 10:00 am #15656Ernest Marcinko
KeymasterHi Quim,
It could be actually doable with a custom code, I believe.
Basically you want a ‘between’ filter, that checks if the date is inbetween the start and the end date. I have made a custom code that may do the trick:1. The code will try to detect the start date filter, and use it as the date to compare. For this, make sure to first delete the end date filter: https://i.imgur.com/Xm6LNaL.png
The start date filter will be used for the inbetween comparision, and the custom code will create the other ‘hidden’ filter to make an inbetween check.2. Add this custom code to the functions.php in your theme/child theme directory (copy from line 3 only!). Before editing, please make sure to have a full site back-up just in case!
3. Make sure that the $field1 and the $field2 variable in the code is correctly set to the start date and the end date custom field.
..that’s it!
November 28, 2017 at 11:51 am #15657Quimm
ParticipantHi Ernest, it works perfect, thank you very much for your time, you deserve more than 5 stars in the ratings.
Now It works all fine I have a doubt about the trigger options of the Date Picker, it didn’t work the live search as checkbox, radio buttons or slider, no?
Thank you!
Quim
November 28, 2017 at 4:52 pm #15660Ernest Marcinko
KeymasterHi Quim,
Thank you for your kind words!
You are correct, that should work as well. Yet another bug I was not aware of 🙂
It took me a while, but I figured out a solution with a custom code for now, until this is fixed with the next update:This should do the trick. If the next update is out (in 2 weeks), you can safely remove this code, as it will no longer be needed.
November 28, 2017 at 7:12 pm #15662Quimm
ParticipantThank you Ernest my client it will be very happy with that! Works perfect!
QuimNovember 28, 2017 at 8:35 pm #15666Ernest Marcinko
KeymasterYou cannot access this content.
November 28, 2017 at 9:42 pm #15667Quimm
ParticipantYou cannot access this content.
-
AuthorPosts
- The topic ‘Search by date range with custom fields datepicker not working’ is closed to new replies.