Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Two Columns sorted by custom field date ( separate )
- This topic has 6 replies, 2 voices, and was last updated 8 years, 1 month ago by
eberswine.
-
AuthorPosts
-
April 8, 2018 at 11:53 pm #17445
eberswine
ParticipantHi, 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!
April 9, 2018 at 10:19 am #17452Ernest Marcinko
KeymasterHi,
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.pngArchived Events search bar
Filter: https://i.imgur.com/cBqVS7F.pngIn 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.
April 9, 2018 at 1:13 pm #17453eberswine
ParticipantThat 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” ?
April 9, 2018 at 2:33 pm #17455Ernest Marcinko
KeymasterHi,
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.
April 9, 2018 at 4:45 pm #17456eberswine
ParticipantYou cannot access this content.
April 9, 2018 at 5:31 pm #17457Ernest Marcinko
KeymasterYou cannot access this content.
April 9, 2018 at 5:43 pm #17458eberswine
ParticipantYes- thanks! I will rate it now!!
-
AuthorPosts
- The topic ‘Two Columns sorted by custom field date ( separate )’ is closed to new replies.