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!
WordPressPHP

Avatar of undefined
Last Comment
eemit

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
eemit

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61