Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Can't put events in date order in search results
This topic contains 13 replies, has 2 voices, and was last updated by Ernest Marcinko 2 months ago.
- AuthorPosts
- November 17, 2022 at 7:46 pm #40003
Hi,
I am trying to use a custom field in an events management plugin (MEC – Modern Events Calendar) in order to show results in DATE order, but NOT the native WordPress ‘creation date’….
1) I have done what I ‘thought’ I needed to do, but it’s not working…this is the link to MECs Custom Fields tutorial on Custom Fields:
https://www.webnus.net/dox/modern-events-calendar/custom-fields/#:~:text=In%20order%20to%20create%20your,set%20a%20label%20for%20it. I tried adding a Custom field in MEC Event data – BUT using custom fields in MEC calendar really just creates an extra field that subsequently displays a piece of text (date as text) on the front – which isn’t helpful as, it duplicates the MEC date field visually, and as far as I can see it’s not searchable and doesn’t help put events in date order of event date rather than creation date (if that makes sense!?)
So, basically I cannot see how this talliies with the Custom fields in the Ajax Pro and how I can find the event date field inside Ajax Pro….
Please see screenshots of what I’ve been trying… any wisdom well received please! Thank you π
Rob
Attachments:
You must be logged in to view attached files.November 18, 2022 at 9:29 am #40014Hi,
Thank you very much for the details, it helps a lot!
Try this custom field:
Best,mec_start_date
Apparently that is the one storing the start dates with that plugin.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
November 18, 2022 at 3:14 pm #40025Hi – really appreciate the help… still struggling!
Wonder if you would mind taking a look at the steps I’ve taken on this video – as you might see something glaring I’m doing wrong?
Many thanks!
November 18, 2022 at 6:32 pm #40027The order actually seems to be correct, that is going to be the right field, the titles are the ones not being correct as it seems.
Best,
For example searching “sustainibility”, clicking on the second result the actual date is different.
The same seems to be with all of the others, althought I only checked a few.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
November 18, 2022 at 6:58 pm #40028Thanks…
I was really excited for a moment, but I ‘think’ you may have stumbled on the exceptions (nevertheless, they all do need checking!)… see attached though…
These are correct but strangely in the wrong order… I just can’t work it out!
You can’t see anything I’m doing / might be wrong? I was wondering about the permalink structure or something like that, but my knowledge doesn’t run deep enough.
Understand if you can’t help – but if you can think of anything else, or if I’m not getting it… please do let me know as it’s taken me hours, and I really love it, and keen to make it work! π
Best
Rob
Attachments:
You must be logged in to view attached files.November 19, 2022 at 9:12 am #40032The ordering field type was set to numeric, I changed it back to “date or string”: https://i.imgur.com/PPIIjTm.png
Best,
Now it looks all right on my end: https://i.imgur.com/XCUA3PO.png
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
November 20, 2022 at 12:27 pm #40036You cannot access this content.November 21, 2022 at 1:02 pm #40054Well this is a tough one, but I guess the best approach is via a custom code.
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.
add_filter("asp_query_args", "asp_query_args_apply_date", 10, 2); function asp_query_args_apply_date($args, $search_id) { $args['post_meta_filter'][] = array( 'key' => 'mec_end_date', 'value' => date("Y-m-d"), 'operator' => '>', 'allow_missing' => false ); return $args; }
I don’t know if this is going to do anything, but it should remove any items from the results, which have the end date before the current date.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
December 1, 2022 at 4:42 am #40317You cannot access this content.December 1, 2022 at 1:22 pm #40332Hi,
The date picker format is usually only for visual purposes only, the actual values are probably stored in the “Y-m-d” format, that is very common. It is more likely a data type issue only.
I have made a correction via the theme file editor, as the code was already there and added extra quote signs to cast the date to a string. Can you check if this changed anything in the results?
For reference, the new code is:
Best,add_filter("asp_query_args", "asp_query_args_apply_date", 10, 2); function asp_query_args_apply_date($args, $search_id) { $args['post_meta_filter'][] = array( 'key' => 'mec_end_date', 'value' => "'" . date("Y-m-d") . "'", 'operator' => '>', 'allow_missing' => false ); return $args; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
December 1, 2022 at 2:12 pm #40337You are an absolute legend… thanks so much!!!!
All fixed π
December 1, 2022 at 2:19 pm #40339Thank you! Great π
If you don’t mind, I will close this topic soon and mark it as resolved, feel free to open another one if you have other questions or issues.
If you like the plugin and have not rated already, feel free to leave a rating on your codecanyon downloads page, it’s greatly appreciated.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
December 1, 2022 at 2:39 pm #40341Brilliant… I have already given it a great review, but will do another for you..
Thanks again
Best
Rob
December 1, 2022 at 2:42 pm #40343Oh, I’m sorry, I just copy/pasted from a default response, I only wanted to ask if I can close the topic π
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.