Link to home
Start Free TrialLog in
Avatar of cstela
cstela

asked on

Modifying get_posts to display children and grandchildren of current page

Hello,
I'm trying to modify my existing loop to include also the sub-sub-pages of my Services page.

<?php 
                global $post;
                $args = array('post_parent' => $post->ID, 'post_type' => 'page', 'posts_per_page' => -1); 
                $custom_posts = get_posts($args);
                foreach($custom_posts as $post) : setup_postdata($post); ?>
                <div class="col-sm-8 col-md-4 service">
                    <div>
                        <header>
                            <h3><?php the_title(); ?></h3>
                        </header>
                        <p><?php the_field('short_description');?></p>
                        <p><a role="button" class="btn btn-primary" href="<?php the_permalink();?>">Learn more</a></p>
                    </div>
                </div>
                <?php endforeach;
                ?>

Open in new window


The problem is that when I change it to get_pages, it doesn't display only pages of my current page, but all pages, and with get_posts I don't know how to add grandchildren in the parameters. Can someone help? Thank you!
ASKER CERTIFIED SOLUTION
Avatar of eemit
eemit
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial