benecaster_episode_deleted
Fires before an episode is permanently deleted from the database. Use this hook to clean up external records — remove entries from a search index, revoke CDN assets, log the deletion, or notify an external system — before the local data is gone.
This hook fires on permanent deletion only, when a user empties the trash or force-deletes an episode. It does not fire when an episode is moved to the trash; use [benecaster_episode_unpublished](/hooks/benecaster_episode_unpublished/) for trash events. The episode post row, meta, and taxonomy terms all still exist in the database when this hook fires, so `get_post()`, `get_post_meta()`, and `get_the_title()` return valid data. Once the hook returns, WordPress proceeds with the deletion.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$episode_id |
int |
— | ID of the episode about to be deleted |
$show_id |
int |
— | ID of the parent show |
Examples
Clean up external records on deletion
add_action( 'benecaster_episode_deleted', function (
int $episode_id,
int $show_id
) {
$audio_url = get_post_meta( $episode_id, '_benecaster_audio_url', true );
// Remove from external analytics platform before the post row is gone.
my_analytics_delete_episode( $episode_id );
// Notify a Slack channel.
my_slack_notify( sprintf(
'Episode deleted: %s (show %d) — audio: %s',
get_the_title( $episode_id ),
$show_id,
$audio_url ?: 'none'
) );
}, 10, 2 );
Notes
The episode still exists in the database when this hook fires — get_post(), get_post_meta(), and get_the_title() all return valid data. Once the hook returns, WordPress permanently removes the post row, meta, and taxonomy terms. This is the last opportunity to read the episode's data.