From d2695fe283ef0b4483fc19115c34f39795447ac8 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Mon, 14 Jan 2019 23:27:50 +0000 Subject: [PATCH] Query: Cache the result when `get_pages()` doesn't find anything in the database. Props flixos90, soulseekah. Fixes #43514. Built from https://develop.svn.wordpress.org/trunk@44587 git-svn-id: http://core.svn.wordpress.org/trunk@44418 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 5 ++++- wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 41fc4709a3..6657e462c4 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -5057,7 +5057,8 @@ function get_pages( $args = array() ) { $last_changed = wp_cache_get_last_changed( 'posts' ); $cache_key = "get_pages:$key:$last_changed"; - if ( $cache = wp_cache_get( $cache_key, 'posts' ) ) { + $cache = wp_cache_get( $cache_key, 'posts' ); + if ( false !== $cache ) { // Convert to WP_Post instances. $pages = array_map( 'get_post', $cache ); /** This filter is documented in wp-includes/post.php */ @@ -5218,6 +5219,8 @@ function get_pages( $args = array() ) { $pages = $wpdb->get_results( $query ); if ( empty( $pages ) ) { + wp_cache_set( $cache_key, array(), 'posts' ); + /** This filter is documented in wp-includes/post.php */ $pages = apply_filters( 'get_pages', array(), $r ); return $pages; diff --git a/wp-includes/version.php b/wp-includes/version.php index 5cee92a0a4..9b03a566a4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-beta1-44586'; +$wp_version = '5.1-beta1-44587'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.