Support

Account

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
    	}	
    ?>