WordPress.org

Forums

delete_post hook problem in WP 3.2.1 (4 posts)

  1. ihjordanov
    Member
    Posted 4 years ago #

    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!

  2. adebaby
    Member
    Posted 4 years ago #

    I have similar issue with custom meta disappearing before the delete_post function is called. Used to work fine

    http://wordpress.org/support/topic/delete_post-order-changed-in-newer-wp

  3. ihjordanov
    Member
    Posted 4 years ago #

    Thanks a lot!
    Your solution working properly.

  4. kg69design
    Member
    Posted 3 years ago #

    adebaby, Thanks for the solution!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags