Query: Cache the result when get_pages() doesn't find anything in the database.

Props flixos90, soulseekah.
Fixes #43514.



git-svn-id: https://develop.svn.wordpress.org/trunk@44587 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2019-01-14 23:26:20 +00:00
parent 464c9a72f0
commit 5cdc0e1397
2 changed files with 26 additions and 1 deletions
+4 -1
View File
@@ -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;