diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index d0bc1a3..39e3625 100644
|
a
|
b
|
function wp_delete_post( $postid = 0, $force_delete = false ) { |
| 2405 | 2405 | // Point children of this page to its parent, also clean the cache of affected children. |
| 2406 | 2406 | $children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type ); |
| 2407 | 2407 | $children = $wpdb->get_results( $children_query ); |
| 2408 | | |
| 2409 | | $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) ); |
| | 2408 | if ( $children ) { |
| | 2409 | $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) ); |
| | 2410 | } |
| 2410 | 2411 | } |
| 2411 | 2412 | |
| 2412 | 2413 | // Do raw query. wp_get_post_revisions() is filtered. |
diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php
index 71fe55e..6c13225 100644
|
a
|
b
|
class Tests_Post extends WP_UnitTestCase { |
| 1229 | 1229 | $this->assertEquals(get_date_from_gmt($post['post_date_gmt']), $out->post_date); |
| 1230 | 1230 | $this->assertEquals($post['post_date_gmt'], $out->post_date_gmt); |
| 1231 | 1231 | } |
| | 1232 | |
| | 1233 | function test_wp_delete_post_reassign_hierarchical_post_type() { |
| | 1234 | $grandparent_page_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); |
| | 1235 | $parent_page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $grandparent_page_id ) ); |
| | 1236 | $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $parent_page_id ) ); |
| | 1237 | $this->assertEquals( $parent_page_id, get_post( $page_id )->post_parent ); |
| | 1238 | wp_delete_post( $parent_page_id, true ); |
| | 1239 | $this->assertEquals( $grandparent_page_id, get_post( $page_id )->post_parent ); |
| | 1240 | wp_delete_post( $grandparent_page_id, true ); |
| | 1241 | $this->assertEquals( 0, get_post( $page_id )->post_parent ); |
| | 1242 | } |
| | 1243 | |
| 1232 | 1244 | } |