ACF datepicker

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 6 years ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #8863
    alphaprojekt
    alphaprojekt
    Participant

    Hello there,

    I currently developing a WordPress website offline. In that site I created a CPT and I use 5 ACF (Advanced Custom Fields by Elliot Condon) fields – one of that field is a datepicker. This is representing the birthday.

    Now I want to be able with your plugin to search by a birthday. So far I understand, that ACF is using the format YYYYMMDD as output. No one will search by “20160501”.

    I set my datepicker field to “d.m.y”.

    Any idea, a trick, a hook to realize this?

    Thanks, Roman

    Attachments:
    You must be logged in to view attached files.
    #8880
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    The ACF plugin will save in a format you give it. If you enter the “Save Format” (Darstellungs-format I believe in german) field as “d.m.y” then it will be stored in a format “1.12.16” for date 1st of december 2016. I just tested this and the database records confirm. In this case if you search “1.12” or “12.16” (or any substring of it) it will match the date, as it’s treated as a string.

    Also, make sure to choose the date again and save the post once more, as ACF will not convert the fields automatically which are already in the database.

    If I may recommend a more widely used format might be “dd.mm.yy”, which includes the full year and leading zeros as well and it looks like “01.12.2016” in the database, and might be much easier to search for as well.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #8947
    alphaprojekt
    alphaprojekt
    Participant
    You cannot access this content.
    #8953
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    To answer your second question first: I think you are looking for the custom field filters: https://goo.gl/6dKjaP
    You can basically create filters based on custom fields with that, including ACF date field. Please note however, that the ACF date picker filter will only work if the default storage method is used with ACF dates, the default “20160501” as you mentioned in your first post. Otherwise the search won’t be able to compare the values.

    And I answered your second question first, because this might lead to a catch 22 situation. Because the search date picker filter only works with the default ACF date storage format (20160501), if you choose to this filter, you won’t be able to use the same custom field to search the way you want it, as the data has to be stored in that format.
    In case you want to use the custom field date search filter and search within the date custom field, I recommend creating 2 separate date fields:
    – one with the ACF default date format to used within the filter
    – second for searching the dates in any format you desire
    I know it sounds silly and all, but I can’t think of any better solution right now.

    Now, to finally answer your first question:

    I understand what you want now. You need to match the date field exactly from it’s beginning, so:

    – “2016” should not match “01/06/2016
    – “01/06” should match “01/06/2016″ (because it begins with it)

    Am I correct?

    Unfortunately that is not how the plugin works. I would rather not go into details why, it’s a very complicated issue, but I think I can offer you a solution, but you will have to modify one of the plugin files.

    I’m assuming you use the regular engine and the “or” keyword logic (defaults):
    0. Before any change, make sure to have a full site back-up, in case anything goes wrong.
    1. Open up the ajax-search-pro\includes\classes\search\search_content.class.php and scroll to lines 540-546, where you should see this:

    2. Change those lines to:

    The difference between these two is that the second does not have a wildcard on the beginning of the query, thus allowing to match strictly from the beginning.

    I hope this covers everything you wanted to know.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


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

You must be logged in to reply to this topic.