Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Show only Future Events
- This topic has 3 replies, 2 voices, and was last updated 2 years, 11 months ago by
Ernest Marcinko.
-
AuthorPosts
-
June 22, 2023 at 3:34 pm #44424
HeinrichMarketing
ParticipantHello Team,
first of all: you are by far the best, most flexible and well thought-out plugin ever!
The following question has already come up several times here.
Unfortunately, I can’t automatically delete the old events in the event plugin, but they should be able to be hidden in the filter at https://cervantes.de/kurse-finden/. Unfortunately, I can’t get any further with the instructions from https://documentation.ajaxsearchpro.com/advanced-options/excluding-and-including-results/exclude-or-include-by-custom-field-values, as I don’t have any programming knowledge.
The event plugin is https://wp-events-plugin.com/documentation/getting-started-guide/. The field should be _event_start_date. But what should the code be called?
I would be very pleased to receive an answer!
Many thanks, Andreas
June 22, 2023 at 3:45 pm #44427Ernest Marcinko
KeymasterHi!
Thank you for your kind words!
Surely it is possible, but you may need a few lines of code for it. I am not exactly sure about the plugin you are using for events, but I have constructed a custom code snippet, which should do exactly that if the date format is what I think it is. You will find it below.
Try adding this code via the Code Snippets plugin or 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' => '_event_start_date', 'value' => date('Y-m-d'), 'operator' => '>=', 'allow_missing' => false ); return $args; }June 22, 2023 at 7:42 pm #44430HeinrichMarketing
ParticipantHi Ernest,
thank you for the code.. unfortunately it does not work… what am i doing wrong? I have put in the code in the functions.php… maybe it is the wrong selector? But how can i find out?
Thank you so much for your help!
Best, Andreas
June 23, 2023 at 11:59 am #44433Ernest Marcinko
KeymasterIt’s likely only the date format and the field. I checked to see and you seem to be using the Events Manager plugin, for that this should work:
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' => '_event_start', 'value' => date('Y-m-d H:i:s'), 'operator' => '>=', 'allow_missing' => false ); return $args; } -
AuthorPosts
- You must be logged in to reply to this topic.