do_action( 'before_delete_post',
$postid,
$post );
delete_post_meta( $postid, '_wp_trash_meta_status'
);
delete_post_meta( $postid, '_wp_trash_meta_time'
);
wp_delete_object_term_relationships( $postid,
get_object_taxonomies( $post->post_type
) );
$parent_data = array
( 'post_parent' =>
$post->post_parent
);
$parent_where = array
( 'post_parent' =>
$postid );
if ( is_post_type_hierarchical( $post->post_type
) ) { // Point children of this page to its parent, also clean the cache of affected children.
$children_query =
$wpdb->
prepare( "SELECT * FROM
$wpdb->posts WHERE post_parent = %d AND post_type = %s",
$postid,
$post->post_type
);
$children =
$wpdb->
get_results( $children_query );
if ( $children ) { $wpdb->
update( $wpdb->posts,
$parent_data,
$parent_where + array
( 'post_type' =>
$post->post_type
) );
} }