Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Can't put events in date order in search results
- This topic has 13 replies, 2 voices, and was last updated 3 years, 6 months ago by
Ernest Marcinko.
-
AuthorPosts
-
November 17, 2022 at 7:46 pm #40003
robwalden
ParticipantHi,
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
November 18, 2022 at 9:29 am #40014Ernest Marcinko
KeymasterHi,
Thank you very much for the details, it helps a lot!
Try this custom field:
mec_start_date
Apparently that is the one storing the start dates with that plugin.November 18, 2022 at 3:14 pm #40025robwalden
ParticipantHi – 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 #40027Ernest Marcinko
KeymasterThe 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.
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.November 18, 2022 at 6:58 pm #40028robwalden
ParticipantThanks…
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
November 19, 2022 at 9:12 am #40032Ernest Marcinko
KeymasterThe ordering field type was set to numeric, I changed it back to “date or string”: https://i.imgur.com/PPIIjTm.png
Now it looks all right on my end: https://i.imgur.com/XCUA3PO.pngNovember 20, 2022 at 12:27 pm #40036robwalden
ParticipantYou cannot access this content.
November 21, 2022 at 1:02 pm #40054Ernest Marcinko
KeymasterWell 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.
December 1, 2022 at 4:42 am #40317robwalden
ParticipantYou cannot access this content.
December 1, 2022 at 1:22 pm #40332Ernest Marcinko
KeymasterHi,
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:
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; }December 1, 2022 at 2:12 pm #40337robwalden
ParticipantYou are an absolute legend… thanks so much!!!!
All fixed 🙂
December 1, 2022 at 2:19 pm #40339Ernest Marcinko
KeymasterThank 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.
December 1, 2022 at 2:39 pm #40341robwalden
ParticipantBrilliant… 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 #40343Ernest Marcinko
KeymasterOh, I’m sorry, I just copy/pasted from a default response, I only wanted to ask if I can close the topic 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.