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, by every route: DELETE /episodes/{id}, wp-admin’s Delete Permanently or Empty Trash, and wp_delete_post() from code or WP-CLI. Deleting a show fires it once for each of the show’s episodes, after benecaster_show_deleted. It does not fire when an episode is moved to the trash; use benecaster_episode_unpublished for trash events.
Everything the episode owns still exists when this hook fires: the post row, meta and taxonomy terms, and its availability dates, reference usage and custom field values, so get_post(), get_post_meta() and get_the_title() return valid data. Benecaster removes the episode’s own rows after the hook returns, and then WordPress deletes the post.
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, Benecaster removes the episode's availability, reference usage and custom field values, and WordPress permanently removes the post row, meta and taxonomy terms. This is the last opportunity to read the episode's data. Reference library items belong to the show and are not deleted with an episode.
Need this built rather than just documented? See our services →