monsterinsights_get_pages

Retrieve a list of all published pages.

Description

(array) monsterinsights_get_pages( (bool) $force = false ); 

On large sites this can be expensive, so only load if on the settings page or $force is set to true

Returns (array)

$pages_options An array of the pages

Parameters (1)

0. $force — Optional. (bool) => false
Force the pages to be loaded even if not on settings

Usage

  1. if ( !function_exists( 'monsterinsights_get_pages' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-analytics-for-wordpress-by-monsterinsights/includes/admin/settings/settings-api.php'; 
  3.  
  4. // Force the pages to be loaded even if not on settings 
  5. $force = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = monsterinsights_get_pages($force); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/admin/settings/settings-api.php  
  1. function monsterinsights_get_pages( $force = false ) { 
  2. $pages_options = array( '' => '' ); // Blank option 
  3. if( ( ! isset( $_GET['page'] ) || 'monsterinsights_settings' != $_GET['page'] ) && ! $force ) { 
  4. return $pages_options; 
  5.  
  6. $pages = get_pages(); 
  7. if ( $pages ) { 
  8. foreach ( $pages as $page ) { 
  9. $pages_options[ $page->ID ] = $page->post_title; 
  10.  
  11. return $pages_options;