// Do raw query. wp_get_post_revisions() is filtered.
$revision_ids =
$wpdb->
get_col( $wpdb->
prepare( "SELECT ID FROM
$wpdb->posts WHERE post_parent = %d AND post_type = 'revision'",
$postid ) );
// Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up.
foreach ( $revision_ids as $revision_id ) { wp_delete_post_revision( $revision_id );
} // Point all attachments to this post up one level.
$wpdb->
update( $wpdb->posts,
$parent_data,
$parent_where + array
( 'post_type' => 'attachment'
) );
wp_defer_comment_counting( true
);
$comment_ids =
$wpdb->
get_col( $wpdb->
prepare( "SELECT comment_ID FROM
$wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC",
$postid ) );
foreach ( $comment_ids as $comment_id ) { wp_delete_comment( $comment_id, true
);
} wp_defer_comment_counting( false
);
$post_meta_ids =
$wpdb->
get_col( $wpdb->
prepare( "SELECT meta_id FROM
$wpdb->postmeta WHERE post_id = %d ",
$postid ) );
foreach ( $post_meta_ids as $mid ) { delete_metadata_by_mid( 'post',
$mid );
}