cliff
2/23/2016 - 8:34 PM

Delete !!! ALL !!! of The Events Calendar's "Events" posts (not Organizers or Venues)

Delete !!! ALL !!! of The Events Calendar's "Events" posts (not Organizers or Venues)

<?php
/**
  * From https://gist.github.com/cliffordp/ee148004b0d8a429095a
  * 
  * Delete !!! ALL !!! of The Events Calendar's "Events" posts (not Organizers or Venues)
  * !!! CAUTION !!!
  * 
  * Must uncomment wp_delete_post() below for it to work. Note its use of TRUE to bypass the WordPress Trash Can!!!
  * 
  */
add_filter( 'wp_loaded', 'cliff_delete_all_tribe_events' );
function cliff_delete_all_tribe_events() {
  $args = array(
  	'posts_per_page'   => -1, // no limit
  	'post_type'        => 'tribe_events', // The Events Calendar's "Events" posts (not Organizers or Venues)
  	'fields'           => 'ids', // only pull the Post IDs
  );
  
  $post_ids = get_posts( $args );
  
  // var_dump( $post_ids );
  
  if ( ! empty ( $post_ids ) && is_array ( $post_ids ) ) {
    foreach ( $post_ids as $id ) {
      // wp_delete_post ( $id, true ); // No UNDO!!!
    }
  }
}