Show only Future Events

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 12 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #44424
    HeinrichMarketing
    HeinrichMarketing
    Participant

    Hello 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

    Attachments:
    You must be logged in to view attached files.
    #44427
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

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

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


    #44430
    HeinrichMarketing
    HeinrichMarketing
    Participant

    Hi 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

    #44433
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

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

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


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

You must be logged in to reply to this topic.