Ludovic Samuel Clain
asked 4 years ago

Hi there,
i have a little problem, when a question, comment or answer contains attachments and it is deleted, the attachments is not,
could you check it on your side and give me a trick please?

1 Answers
answered 4 years ago

At the moment, you can add the following code to the functions.php file to delete the attachment when a question is deleted.

function delete_post_children($post_id) {
  global $wpdb;
  if ( get_post_type( $post_id ) == 'dwqa-question' ) {
    $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('before_delete_post', 'delete_post_children');

However, you only possible manual delete attachment for the answer.
We will check and discuss about this option.

Powered by DW Question & Answer Pro