mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 09:37:42 +01:00
Update hierarchy for all hierarchical post types when deleting a parent post, not just for pages. Fixes #19637.
git-svn-id: http://svn.automattic.com/wordpress/trunk@19734 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
cd43f96110
commit
fab149d81e
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user