Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I know how to display content from one page on another page. Here is the code I use to display the last three video-titles, submitted to my video-page, on another page (using Advanced Custom Fields for the content)

<?php
$other_page = 5;
?>
<?php if(get_field('video', $other_page)): $count = 0; ?>
<?php while (the_repeater_field('video', $other_page)): $count++; ?>
<?php the_sub_field('video_title'); ?>      
<?php if($count==3) break; ?>   
<?php endwhile; ?>
<?php endif; ?> 

But what I want to do is to display content from the last three video-subpages, and not just the content displayed on the video page itself. Does anyone know how to do this? :)

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

you can use the number param to limit the number of pages you want and get the custom field in the foreach loop :) (child of = your parent page, or the current page)

$mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc', 'number' => 3, ) );

foreach( $mypages as $page ) {      
    $content = $page->post_content;
    $content = apply_filters( 'the_content', $content );
    ?>
      <h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2>
      <div class="entry"><?php echo $content; ?></div>
   <?php
}

http://codex.wordpress.org/Function_Reference/get_pages

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.