Can't put events in date order in search results

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 Ernest Marcinko 2 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #40003
    robwalden
    robwalden
    Participant

    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.
    #40014
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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.

    Best,
    Ernest Marcinko

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


    #40025
    robwalden
    robwalden
    Participant

    Hi – 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!

    https://www.loom.com/share/361cca80f8df467ebcc8da288c64f619

    #40027
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    The 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.

    Best,
    Ernest Marcinko

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


    #40028
    robwalden
    robwalden
    Participant

    Thanks…

    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.
    #40032
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    The 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.png

    Best,
    Ernest Marcinko

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


    #40036
    robwalden
    robwalden
    Participant
    You cannot access this content.
    #40054
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Well 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 :)


    #40317
    robwalden
    robwalden
    Participant
    You cannot access this content.
    #40332
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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;
    }
    Best,
    Ernest Marcinko

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


    #40337
    robwalden
    robwalden
    Participant

    You are an absolute legend… thanks so much!!!!

    All fixed πŸ™‚

    #40339
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Thank 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 :)


    #40341
    robwalden
    robwalden
    Participant

    Brilliant… I have already given it a great review, but will do another for you..

    Thanks again

    Best

    Rob

    #40343
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Oh, 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 :)


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

You must be logged in to reply to this topic.