Skip to content

Instantly share code, notes, and snippets.

@codingmusician
Last active February 19, 2019 14:39
Show Gist options
  • Save codingmusician/c33994c8d2c1a69aa94cc73d52d37ff2 to your computer and use it in GitHub Desktop.
Save codingmusician/c33994c8d2c1a69aa94cc73d52d37ff2 to your computer and use it in GitHub Desktop.
<?php
/**
* Description: Trash expired events automatically
*
* Usage: copy the snippet in your active (child) theme's functions.php file
*
* Plugins: The Events Calendar
* Author: Modern Tribe
* Last updated: February 19, 2019
*/
function tribe_trash_event_after_expiration(){
if(is_admin()){
return;
}
$args = ["end_date" => date("Y-m-d 23:59:59", strtotime("yesterday", current_time("timestamp"))), "posts_per_page" => 50];
$events = tribe_get_events($args);
foreach($events as $e){
wp_trash_post($e->ID);
}
}
add_action("init", "tribe_trash_event_after_expiration");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment