Created
April 10, 2020 12:29
-
-
Save tiendungdev/dc66887c36b5b53b4fcd8a4a4971192f to your computer and use it in GitHub Desktop.
Get child pages of a page in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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