Skip to content

Instantly share code, notes, and snippets.

@anova
Last active March 15, 2022 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anova/b78eda0db2d7a8748c510e7e9ab5172e to your computer and use it in GitHub Desktop.
Save anova/b78eda0db2d7a8748c510e7e9ab5172e to your computer and use it in GitHub Desktop.
<?php
// get_pages
$pages = get_pages( [
'child_of' => $id,
//'sort_column' => 'rand',
'sort_column' => 'menu_order',
'post_status' => 'publish,draft',
] );
// WP_Query
$pages_query = new WP_Query( [
'post_type' => 'page',
'post_parent' => $id,
//'orderby' => 'rand',
'orderby' => 'menu_order',
'order' => 'ASC',
'post_status' => 'publish,draft',
'posts_per_page' => -1,
'has_password' => false,
] );
$pages_query_array = [];
while( $pages_query->have_posts() ):
$pages_query->the_post();
array_push( $pages_query_array, get_post( get_the_ID() ) );
endwhile;
wp_reset_postdata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment