From: Steve Sutton Date: Wed, 20 Dec 2017 18:53:27 +0000 (-0500) Subject: use static for the good page ids X-Git-Tag: v1.0.6^2~5 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=4f9c9e6f6dd6e0ab8b5e39dc5c7a280eb9729c21;p=WP-Themes%2FAdelaineConstruction.git use static for the good page ids to prevent hitting database twice. --- 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;