From 4f9c9e6f6dd6e0ab8b5e39dc5c7a280eb9729c21 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 20 Dec 2017 13:53:27 -0500 Subject: [PATCH] use static for the good page ids to prevent hitting database twice. --- functions.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/functions.php b/functions.php index 30c6523..101ebbf 100644 --- a/functions.php +++ b/functions.php @@ -98,17 +98,19 @@ add_filter('pre_get_posts','SearchFilter'); function glm_get_visable_page_ids() { - $publishPageIds = array(); - // Find all pages marked published - $publishedPages = get_pages( - array( - 'post_type' => 'page', - 'post_status' => 'publish', - ) - ); - foreach ( $publishedPages as $page ) { - if ( !$page->post_password ) { - $publishPageIds[] = $page->ID; + static $publishPageIds = array(); + if ( empty( $publishPageIds ) ) { + // Find all pages marked published + $publishedPages = get_pages( + array( + 'post_type' => 'page', + 'post_status' => 'publish', + ) + ); + foreach ( $publishedPages as $page ) { + if ( !$page->post_password ) { + $publishPageIds[] = $page->ID; + } } } return $publishPageIds; -- 2.17.1