Skip to content

Instantly share code, notes, and snippets.

@robertdevore
Last active May 9, 2018 19:20
Show Gist options
  • Select an option

  • Save robertdevore/128995d5ac92dcc427d561c5e77ae4e1 to your computer and use it in GitHub Desktop.

Select an option

Save robertdevore/128995d5ac92dcc427d561c5e77ae4e1 to your computer and use it in GitHub Desktop.
Create array of all pages in WordPress.
<?php
// Get loop of all Pages.
$args = array(
'sort_column' => 'post_title',
'hierarchical' => 1,
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages( $args );
// Create data array.
$data = array( 'none' => '' );
// Loop through pages.
foreach ( $pages as $page ) {
// Add page to $data array.
$data[ $page->ID ] = $page->post_title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment