So I have a link that removes a post.
I also have some code in my functions.php wich should be hooked to the wp_delete() function.
However. The function doesn't seem to work. What am I doing wrong?
<p><a href="<?php echo get_delete_post_link( get_the_ID()); ?>">Delete Papercraft</a></p>
Here is the function
function delete_post_children($post_id) {
global $wpdb;
$ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_parent = $post_id AND post_type = 'attachment'");
foreach ( $ids as $id )
wp_delete_attachment($id);
}
add_action('before_delete_post', 'delete_post_children');