Support

Account

Home Forums Front-end Issues Parent page with children page content

Helping

Parent page with children page content

  • Is it possible to get ACF fields from child page and have them appear on the parent page.

    What I have been trying to do is have a parent page which then has some child pages in it’s structure which all show brief snippet written from that child page and then if I add more it shows them automatically etc.

    Here is what I have so far;

    <?php
    $childArgs = array(
        'sort_order' => 'ASC',
        'sort_column' => 'menu_order',
        'child_of' => get_the_ID()
    );
    $childList = get_pages($childArgs);
    foreach ($childList as $child) { ?>
        <div class="child-page">
            <h2 class="child-title"><?php echo $child->post_title; ?></h2>
            <?php echo apply_filters( 'the_content', $child->post_content); ?>
            <a href="<?php echo get_permalink(); ?>">...more</a>
        </div>
    <?php } ?>

    I am struggling getting my head around how I can get the fields from child pages without listing a specific ID…

    Can anyone help?

  • Hi @forbiddenchunk

    You can simply get the child ID from the $child variable like this:

    $field_value = get_field('custom_field_name', $child->ID);
    echo $field_value;

    This page should give you more idea about it: https://www.advancedcustomfields.com/resources/get_field/.

    I hope this helps 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.