diff --git a/wp-includes/post.php b/wp-includes/post.php index b8c229a0d9..c1b6f625c3 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1984,6 +1984,14 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { $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 ); + + $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) ); + } + if ( 'page' == $post->post_type) { // if the page is defined in option page_on_front or post_for_posts, // adjust the corresponding options @@ -1994,12 +2002,6 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { if ( get_option('page_for_posts') == $postid ) { delete_option('page_for_posts'); } - - // 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='page'", $postid); - $children = $wpdb->get_results($children_query); - - $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'page' ) ); } else { unstick_post($postid); } @@ -2035,13 +2037,15 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { if ( 'page' == $post->post_type ) { clean_page_cache($postid); - - foreach ( (array) $children as $child ) - clean_page_cache($child->ID); } else { clean_post_cache($postid); } + if ( is_post_type_hierarchical( $post->post_type ) ) { + foreach ( (array) $children as $child ) + clean_post_cache( $child->ID ); + } + wp_clear_scheduled_hook('publish_future_post', array( $postid ) ); do_action('after_delete_post', $postid);