I'm trying to delete all attached files before a post is deleted.
But hook called my function after a post is deleted.
There is my code:
function delete_post_children($post_id) {
global $wpdb;
if (get_post_type( $post_id )=="property") {
$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,true);
}
}
add_action('delete_post', 'delete_post_children');
This problem appears, after i updated to WP 3.2.1
Can anyone help me ?
Thanks!