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
<pre>
<?php print_r($package); ?>
<pre>
<?php
}
?>
<?php endwhile; ?>
<?php endif; ?>
</section>
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
Cheers
webecho