Created
October 22, 2024 19:05
-
-
Save andrasguseo/aa92c541d07de79fbfcb21d7faea6714 to your computer and use it in GitHub Desktop.
ET > Trash (or delete) orphaned tickets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Trash (or delete) orphaned Tickets Commerce tickets. | |
* | |
* Usage: Add the snippet with a plugin like Code Snippets. | |
* Save it as a "Run once" snippet. | |
* Go to the All Snippets page and run the snippet. | |
* | |
* @author: Andras Guseo | |
* | |
* Plugins required: Event Tickets | |
* | |
* @since October 22, 2024 | |
* Initial version. | |
*/ | |
add_action( 'wp_head', function () { | |
// Get the post ID of all the tickets. | |
$all_tickets = tribe_tickets()->per_page( -1 )->get_ids(); | |
foreach ( $all_tickets as $ticket_id ) { | |
// Get the post ID the ticket is linked to. | |
$event_id = get_post_meta( $ticket_id, '_tec_tickets_commerce_event', true ); | |
// If there is no post tied to the ticket... | |
if ( is_null( get_post( $event_id ) ) ) { | |
// To put the tickets in the trash. | |
wp_update_post( | |
[ | |
'ID' => $ticket_id, | |
'post_status' => 'trash' | |
] | |
); | |
// To delete tickets. Note, trashed tickets will not be deleted anymore. | |
// wp_delete_post( $ticket_id, true ); | |
} | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment