Get chiled pages

<?php 
function wpb_list_child_pages() {
	global $post; 
	$args = array(
        'post_type' => 'page',
        'post_parent' => $post->post_parent,
        'post__not_in' => array($post->ID),
        'posts_per_page' => -1,
    );
	 $the_query = new WP_Query( $args ); 
	 ob_start();?>
	 <div class="recentpage-sidebar-row">
	<?php  if ( $the_query->have_posts() ) : 
	 while ( $the_query->have_posts() ) : $the_query->the_post();
	 ?>
	
	<div class="recentpage-content">
				<div class="recentpage-thumb">
					 <a href="<?php the_permalink(); ?>" rel="post-<?php the_ID(); ?>" <?php post_class(); ?>><?php the_post_thumbnail(); ?></a>
				</div>
				<div class="recentpage-title">
                <a href="<?php the_permalink(); ?>" rel="post-<?php the_ID(); ?>" <?php post_class(); ?>><?php the_title(); ?></a>
				</div>
	</div>
	<?php endwhile; 
	endif; 
	wp_reset_postdata() ;?>
	</div>
	<?php return ob_get_clean();
	}
add_shortcode('wpb_childpages', 'wpb_list_child_pages'); ?>

Leave a comment