From a1879766ed4e95eab66ac4694aea3a5d4a9c9030 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 12 Oct 2017 15:20:47 +0000 Subject: [PATCH] Bump 'posts' query cache incrementor when modifying postmeta. This ensures that the `get_pages()` query cache doesn't go stale when postmeta is modified. Props spacedmonkey. Fixes #40669. Built from https://develop.svn.wordpress.org/trunk@41849 git-svn-id: http://core.svn.wordpress.org/trunk@41683 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 24 ++++++++++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index e52ae5776b..d82e8a4d40 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1728,7 +1728,11 @@ function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) { if ( $the_post = wp_is_post_revision($post_id) ) $post_id = $the_post; - return add_metadata('post', $post_id, $meta_key, $meta_value, $unique); + $added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique ); + if ( $added ) { + wp_cache_set( 'last_changed', microtime(), 'posts' ); + } + return $added; } /** @@ -1751,7 +1755,11 @@ function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) { if ( $the_post = wp_is_post_revision($post_id) ) $post_id = $the_post; - return delete_metadata('post', $post_id, $meta_key, $meta_value); + $deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value ); + if ( $deleted ) { + wp_cache_set( 'last_changed', microtime(), 'posts' ); + } + return $deleted; } /** @@ -1793,7 +1801,11 @@ function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) if ( $the_post = wp_is_post_revision($post_id) ) $post_id = $the_post; - return update_metadata('post', $post_id, $meta_key, $meta_value, $prev_value); + $updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value ); + if ( $updated ) { + wp_cache_set( 'last_changed', microtime(), 'posts' ); + } + return $updated; } /** @@ -1805,7 +1817,11 @@ function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) * @return bool Whether the post meta key was deleted from the database. */ function delete_post_meta_by_key( $post_meta_key ) { - return delete_metadata( 'post', null, $post_meta_key, '', true ); + $deleted = delete_metadata( 'post', null, $post_meta_key, '', true ); + if ( $deleted ) { + wp_cache_set( 'last_changed', microtime(), 'posts' ); + } + return $deleted; } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 6d545f3877..e3a889a48c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-beta2-41848'; +$wp_version = '4.9-beta2-41849'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.