Home › Forums › Front-end Issues › List items (and their ACFields) from Child pages on Parent page › Reply To: List items (and their ACFields) from Child pages on Parent page
I have a solution for you! I used the code from the bottom of Function Reference/get pages
and figured out by trial and error that <?php echo the_field('your_field_id', $page->ID); ?>
does the trick to display field data from the child pages.
Final code (including post thumbnail if you want):
<?php
$mypages = get_pages( array( 'child_of' => $post->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 );
?>
<?php echo get_the_post_thumbnail($page->ID); ?>
<h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2>
<p>Custom field info: <?php echo the_field('your_field_id', $page->ID); ?> </p>
<div class="entry"><?php echo $content; ?></div>
<?php
}
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.