Get post id during `delete_post` action in WordPress?

I have this code

add_action( 'delete_post', 'my_delete_function' );
 function my_delete_function() { 
   global $wpdb;
   $wpdb->query("
    DELETE FROM wp_votes WHERE post=".$thePostID."
;);
 }

How can I get the id of the post being deleted?

Read More

Additionally, will this still work if multiple posts are deleted in the admin?

Related posts

Leave a Reply

1 comment

  1. The hooks automatically pass the deleted post id into your function, so you can just catch that, check the docs here:

    add_action( 'delete_post', 'my_delete_function' );
    function my_delete_function($postId) { 
       global $wpdb;
       $wpdb->query("
           DELETE FROM wp_votes WHERE post=".$postId."
       ;);
    }