we caboodle News

Get Child Pages of Parent in WordPress with Advanced Custom Fields

News Categories: Wordpress

This article was published on: 03/11/20 4:49 PM

How to get Child Pages of Parent in WordPress with Advanced Custom Fields

In a recent white label website development, the client of a housing development company required a bespoke house listing and we love using ACF Pro for all our projects as we think it’s user-friendly for the customer in the back end.

If you use ACF then getting them to show on the front end can be tricky, especially if you put them in a group or repeater field, below is the code we used to get the child page house type listings for the housing development which is a parent page.

Get the ‘house_details’ which is the ACF group within the WordPress admin panel

$housedet = get_field(‘house_details’, $page->ID);?>

If you have any questions please comment below or drop us an email for any help of advice.


$ancestor_id = $post->$page_id = get_queried_object_id();
$descendants = get_pages(array('child_of' => $ancestor_id));
$incl = "";
foreach ($descendants as $page) {
if (($page->post_parent == $ancestor_id) ||
($page->post_parent == $post->post_parent) ||
($page->post_parent == $post->ID)){
$incl .= $page->ID . ",";}}?>

<?php $mypages = get_pages( array( 'child_of' => $ancestor_id, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) ); foreach( $mypages as $page ) {$content = $page->post_content; if ( ! $content ) // Check for empty page continue; $content = apply_filters( 'the_content', $content );

$housedet = get_field('house_details', $page->ID);?>

<div class="col span_1_of_3 feathome"><a href="<?php echo get_page_link( $page->ID ); ?>">

<?php echo get_the_post_thumbnail( $page->ID, 'large' ); ?>
<h2 class="txtgrey"><?php echo $page->post_title; ?></h2>
<p class="gofull txtgrey"><?php echo $housedet['house_type_description']; ?></p>

<p class="gofull">Prices from <?php echo get_field( 'house_type_prices_from', $page->ID ); ?></p>
<p class="gofiftylf txtteal"><i class="far fa-bed"></i> <?php echo $housedet['bedrooms']; ?></p>
<p class="gofiftylf txtteal"><i class="far fa-bath"></i> <?php echo $housedet['bathrooms']; ?></p>
<p class="gofiftylf txtteal"><i class="far fa-home"></i> <?php echo get_field( 'square_ft', $page->ID ); ?> sq.ft.</p>
<p class="gofull txtpurple" style="text-decoration: underline">View this home</p>
<?php } ?>
we caboodle - full service agency team

Ready to Start?

we are driven by the challenge of building a bespoke website for your business, improve SEO performance, fix UX/UI issues and streamline your branding across all social & paid channels.

Are you looking for a new, full service agency? contact us today for a free quotation or advice, and lets build something great, together!





    William Holt

    Meet Will

    I've been designing & developing websites for over 2 decades. my first project was built on Microsoft Frontpage, yes I go that far back!

    Speak to me direct regarding your next project or the benefits of switching your digital agency to Web Caboodle

    will@wecaboodle.com | 07368 229004 | LinkedIn Profile

    Web Design Manchester

    Studio 13
    Woolden Road

    Web Design London

    71-75 Shelton Street
    Covent Garden

    let's connect


    Copyright 2023 Web Caboodle - Web Design and Development Agency | We Website Design Ltd 13127888 Registered in England and Wales | Privacy Policy