This page redirects to an external site: https://developer.wordpress.org/reference/hooks/delete_post/
delete_post is fired before and after a post (or page) is deleted from the database.
However by this time the post comments and metadata have been already deleted. Use the before_delete_post hook to catch post deletion before that.
Let's suppose you have a plugin that, for one reason or another, stores its own post metadata in a separate database table called codex_postmeta. One of the ways you can achieve synchronisation is to be made aware when a post is deleted so that you can replicate the changes yourself.
<code style="color: #000000"><span style="color: #0000BB"><?php
add_action</span><span style="color: #007700">( </span><span style="color: #DD0000">'admin_init'</span><span style="color: #007700">, </span><span style="color: #DD0000">'codex_init' </span><span style="color: #007700">);
function </span><span style="color: #0000BB">codex_init</span><span style="color: #007700">() {
</span><span style="color: #0000BB">add_action</span><span style="color: #007700">( </span><span style="color: #DD0000">'delete_post'</span><span style="color: #007700">, </span><span style="color: #DD0000">'codex_sync'</span><span style="color: #007700">, </span><span style="color: #0000BB">10 </span><span style="color: #007700">);
}
function </span><span style="color: #0000BB">codex_sync</span><span style="color: #007700">( </span><span style="color: #0000BB">$pid </span><span style="color: #007700">) {
global </span><span style="color: #0000BB">$wpdb</span><span style="color: #007700">;
if ( </span><span style="color: #0000BB">$wpdb</span><span style="color: #007700">-></span><span style="color: #0000BB">get_var</span><span style="color: #007700">( </span><span style="color: #0000BB">$wpdb</span><span style="color: #007700">-></span><span style="color: #0000BB">prepare</span><span style="color: #007700">( </span><span style="color: #DD0000">'SELECT post_id FROM codex_postmeta WHERE post_id = %d'</span><span style="color: #007700">, </span><span style="color: #0000BB">$pid </span><span style="color: #007700">) ) ) {
</span><span style="color: #0000BB">$wpdb</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">( </span><span style="color: #0000BB">$wpdb</span><span style="color: #007700">-></span><span style="color: #0000BB">prepare</span><span style="color: #007700">( </span><span style="color: #DD0000">'DELETE FROM codex_postmeta WHERE post_id = %d'</span><span style="color: #007700">, </span><span style="color: #0000BB">$pid </span><span style="color: #007700">) );
}
}
</span><span style="color: #0000BB">?></span></code>