Support

Account

Home Forums General Issues How to display fields from child pages on parent page

Solved

How to display fields from child pages on parent page

  • Hi!

    I added custom fields to child pages and on parent page I am listing child pages.

    I get titles and featured images displayed…but I can not get custom field value.

    I can get it to work when I go to child page but not on parent page.

    
    	<?php
    					$mypages = get_pages( array( 'child_of' => $post->ID,'parent' => $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 );
    					?>
    					<div class="one-half">
    						<h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2>
    						<?php echo get_the_post_thumbnail( $page->ID, 'subpage' ); ?>
    						<p><?php the_field('description'); ?>...</p>
    	
    						<a href="<?php echo get_page_link( $page->ID ); ?>" class="more-button"></a>
    					</div>
    						
    					<?php
    						}	
    					?>
    

    Thanks!

  • you have to use the post/page-ID there too. (else it search only at current page)
    probably this works:

    $description = get_field( 'description', $page->ID );
    echo $description;
  • Thanks mediawerk,

    this solved my problem 🙂

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

You must be logged in to reply to this topic.