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

Two Columns sorted by custom field date ( separate )

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Two Columns sorted by custom field date ( separate )

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #17445
    eberswineeberswine
    Participant

    Hi, I had a quick question about a custom field sorting option.

    We have an Events Custom Post Type with a custom field as a date:

    event_date

    We have 7k events on our webpage and wanted to :

    A- Have “Two Columns”
    – One column ( Future Events ) would be sorted by a condition that the custom field “event_date >= CURDATE”
    – The other column ( Archived Events ) would be sorted by a condition that the custom field “event_date <= CURDATE”

    so the user could recognize easily between the different results. We need the older ones to show up because we have “CLAIM YOUR RACE” on those single pages to be updated by Race Directors.

    Couldn’t find a solution. Thanks!

    #17452
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    I believe the easiest solution is to make two separate search bars, one for the Future events and one for the Archived events. Then create a filter for both cases, so that events before/after are filtered out. If the frontend search settings are disabled, these filters will be hidden from the user.

    Future events search bar
    Create a filter like this: https://i.imgur.com/rdWVWib.png

    Archived Events search bar
    Filter: https://i.imgur.com/cBqVS7F.png

    In these examples I’m assuming the dates are stored in a datetime format. It works for most cases. If you know it’s stored differently, then change the Date storage format option accordingly.

    #17453
    eberswineeberswine
    Participant

    That works! Great thank you.

    I wonder if there is a way to have a “checkbox” to select for “Search Past Events”

    And have the default search be “future” ?

    #17455
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    You are welcome! It might be actually possible, using a custom code. I have constructed a possible solution, I am not sure if it works correctly in every case, it does on my test environment, so worth a try.

    1. Make sure to delete the previously suggested filters, and make a single checkbox filter with this exact configuration: https://i.imgur.com/xQFHRI1.png
    The Custom field and the Type and the Value fields are important, the rest does not matter in this case.

    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!

    This code will detect this filter and transform it to a date filter instead – depending on the checkbox state.

    After that, save the options, and try it. If I am not mistaken, then this should likely work.

    #17456
    eberswineeberswine
    Participant

    You cannot access this content.

    #17457
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

    #17458
    eberswineeberswine
    Participant

    Yes- thanks! I will rate it now!!

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Two Columns sorted by custom field date ( separate )’ is closed to new replies.