Home Forums ACF PRO Show Child Fields on Parent page


Show Child Fields on Parent page

  • I have a Parent Page “SEO”
    Child Pages > “Local SEO”, “Essential SEO”

    What i’d like to do is fill out details on the child pages and have them show on the parent page.

    I’ve tried a heap of ways and I can’t get the ACF fields from the Child Pages to show up.

    Have stripped code back to make it simple:

    <section id="service">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<!-- 	<?php the_content(); ?> -->
    <?php $pages = array('child_of' => $post->ID, 'parent' => $post->ID );
    $packages = get_pages($pages);
    foreach ($packages as $package){ 
    echo '=========' . $package->post_title . '==============';
    <?php the_field('title'); ?> // Does Nothing
    <?php the_field('title', $post->ID); ?>	 // Does Nothing
    <?php the_field('title', $page->ID); ?>	// Gives Notice:  Trying to get property of non-object error	
    <?php print_r($package); ?>
    <?php endwhile; ?>
    <?php endif; ?>

    I’ve used print_r($package) and it is correctly picking up the Parent and Child IDs (trimmed for brevity):

    =========Essential SEO==============
    WP_Post Object
        [ID] => 186
        [post_title] => Essential SEO
        [post_parent] => 174
    =========Local SEO==============
    WP_Post Object
        [ID] => 259
        [post_title] => Local SEO
        [post_parent] => 174

    I’ve tried 3 options to get the fields:
    <?php the_field(‘title’); ?> // Does Nothing
    <?php the_field(‘title’, $post->ID); ?> // Does Nothing
    <?php the_field(‘title’, $page->ID); ?> // Gives Notice: Trying to get property of non-object error

    Obviously I’m missing how to get access to the Child pages – but I can’t work out how.

    Be very grateful for any advice



  • Solved!

    I needed to use $package->ID … of course.

    Can I delete the Post? – was just a stupid error

  • but not a unique error. I was going to point out what you found. The entire thing can probably be deleted if you really want but it may help someone else down the road, it also show how to get fields from child posts which could also be useful to someone. All in all a good topic.

  • You’re right John.
    I’ll leave it up as it might help someone else

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

The topic ‘Show Child Fields on Parent page’ is closed to new replies.