Skip to content

Instantly share code, notes, and snippets.

@tiendungdev
Created April 10, 2020 12:29
Show Gist options
  • Save tiendungdev/dc66887c36b5b53b4fcd8a4a4971192f to your computer and use it in GitHub Desktop.
Save tiendungdev/dc66887c36b5b53b4fcd8a4a4971192f to your computer and use it in GitHub Desktop.
Get child pages of a page in WordPress
<?php
$args = array(
'post_type' => 'page', //write slug of post type
'posts_per_page' => -1,
'post_parent' => '26', //place here id of your parent page
'order' => 'ASC',
'orderby' => 'menu_order'
);
$childrens = new WP_Query( $args );
if ( $childrens->have_posts() ) : ?>
<?php while ( $childrens->have_posts() ) : $childrens->the_post(); ?>
<div class="children" id="child-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><?php the_content(); ?></p>
</div>
<?php endwhile;
endif;
wp_reset_query();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment