Clear post cache after updating menu order for products. (#34195)

This commit is contained in:
Barry Hughes 2022-08-15 07:28:14 -07:00 committed by GitHub
parent 2ab9398167
commit 7021d442bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Ensure changes to product order are reflected even when advanced post caching is in effect.

View File

@ -1905,7 +1905,11 @@ class WC_AJAX {
}
$index ++;
$menu_orders[ $id ] = $index;
$wpdb->update( $wpdb->posts, array( 'menu_order' => $index ), array( 'ID' => $id ) );
if ( $wpdb->update( $wpdb->posts, array( 'menu_order' => $index ), array( 'ID' => $id ) ) ) {
// We only need to clean the cache if the menu order was actually modified.
clean_post_cache( $id );
}
/**
* When a single product has gotten it's ordering updated.
@ -1923,7 +1927,10 @@ class WC_AJAX {
$menu_orders[ $sorting_id ] = 0;
}
$wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_orders[ $sorting_id ] ), array( 'ID' => $sorting_id ) );
if ( $wpdb->update( $wpdb->posts, array( 'menu_order' => $menu_orders[ $sorting_id ] ), array( 'ID' => $sorting_id ) ) ) {
// We only need to clean the cache if the menu order was actually modified.
clean_post_cache( $sorting_id );
}
WC_Post_Data::delete_product_query_transients();