• Resolved MacDoodle

    (@macdoodle)


    Is there a way with either the free or pro version of MEC to have expired, non-repeating events automatically deleted?

    I’ve gone thru / searched the documentation / forum a few times, entirely possible I missed this answer because I’m not looking for the right terms. ??

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor webnus

    (@webnus)

    Hello @macdoodle,

    Unfortunately, this option is not available. But please submit your requests here: https://webnus.net/feature-request/, and if your request is already submitted, you can vote for it.

    We would check them, and the one with votes would be selected to be included in the next updates.

    Best Regards

    Hello @macdoodle ,

    Add below to functions.php file of your theme (or use it in a plugin)
    it is a cron job scheduler, which will remove all expired events.

    (It will actually make them draft, but there’s commented out line for removing them in case you need)

    register_activation_hook(__FILE__, 'wojciech_borowicz_mec_cron_job_schedule');
     
    function wojciech_borowicz_mec_cron_job_schedule() {
        if (! wp_next_scheduled ( 'wojciech_borowicz_remove_expired_events_cron_job' )) {
        wp_schedule_event(time(), 'daily', 'wojciech_borowicz_remove_expired_events_cron_job');
        }
    }
     
    add_action('wojciech_borowicz_remove_expired_events_cron_job', 'wojciech_borowicz_remove_expired_events');
     
    function wojciech_borowicz_remove_expired_events() {
        $args = array(
        'post_type' => 'mec-events', 
        'orderby' => 'date',
        'order' => 'DESC',
        'posts_per_page'=> '-1', 
        );
        $loop = new WP_Query( $args );
        if( $loop->have_posts() ):
        $today =  date('Y-m-d');
        while( $loop->have_posts() ): $loop->the_post(); global $post;
         
            $endDate = get_post_meta($post->ID, "mec_end_date", true);
            if($today>$endDate && $endDate!=""){
            //wp_delete_post($post->ID);
            $post = array( 'ID' => $post->ID, 'post_status' => "draft" );
            wp_update_post($post);
          }
       
        endwhile;
        endif;
    }
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Auto Delete Expired Events?’ is closed to new replies.