Scott Eldo
Scott Eldo

Reputation: 473

Show number of child pages the current parent has

I have a Parent page in Wordpress and am using the below code to display information about each of the child pages the parent has. Perfect. What I need to do elsewhere on the page is display the count of child pages, for example 'This page has X child pages'. Can anyone help me to do this please?

    <?php
    $args = array(
        'post_type'      => 'property',
        'posts_per_page' => -1,
        'post_parent'    => $post->ID,
        'order'          => 'ASC',
        'orderby'        => 'menu_order'
     );     
    $parent = new WP_Query( $args );    
    if ( $parent->have_posts() ) :  
    ?>
        <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>

                //content goes here

        <?php endwhile; ?>
    <?php endif; wp_reset_query(); ?>

Upvotes: 1

Views: 3578

Answers (1)

Bhumi Shah
Bhumi Shah

Reputation: 9476

You can use like

$pages = get_pages( array( 'child_of' => $post->ID, 'post_type' => 'property'));
$count = count($pages);

Upvotes: 2

Related Questions