0

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');

1 Answer 1

0

I've found out why it doesn't work. My attachments were only added to the media library and weren't attached to the post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.