I am attempting to get 3 pages from the parent page (id is 2035). I am using wordpress 3.2.1.

Here's my relevant code:

<div id="videos" class="contentLeft"> 
// get the three most recent videos (2035 is the video page)
$recentVideos = get_pages('child_of=2035&number=3');

foreach ($recentVideos as $video) : 
<div class="video">
    <h5 class="video-title"><?php echo $video->post_title; ?></h5> 
    <?php echo get_the_post_thumbnail($video->ID, 'thumbnail'); ?>
    <p><?php echo $video->post_excerpt; ?></p>
    <span class="date">Posted <?php echo date('d/m/Y', strtotime($video->post_date));?> 
    &mdash; <a href="<?php echo get_page_link($video->ID); ?> ">View Video</a></span>

<?php endforeach; ?>

If I use: $recentVideos = get_pages('child_of=2035'); I get results as I would expect; but I want to limit it to 3 videos. I've looked in the docs and it says to use number=X.

When I use this; I simply get a blank content area. The rest of the page renders fine, except where the videos should be. There is no output at all; or errors; as far as I can tell.

Am I missing anything glaringly obvious?

I've also tried passing get_pages an array:

$recentVideos = get_pages(array('child_of'=>2035, 'number'=>3));

but the same thing happens.

Thank you.

1 Answer 1


According to what I read it is because of an odd implementation of that function, apparently the number is used to add a Limit statement to the SQL that is used to get the pages. Then it applies the child_of requirement after retrieving the data from the database. So if you limit the query to 3 chances are you will not get any results that are also a child_of your page.

Instead leave the number parameter off and do the limit in your foreach block. Ie increment a variable and if it is greater than your limit, exit the for loop.

  • 2
    Another alternative is using get_posts() with post_type and numberposts parameters.
    – Michal Mau
    Commented Aug 17, 2011 at 15:46
  • @Maugly Why not add this as an answer?
    – kaiser
    Commented Aug 17, 2011 at 15:55
  • That makes good sense; thanks. I considered a manual limit but wanted to check if it was WP or me causing problems. @Maugly Will look in to the alternative as well; thanks.
    – dave
    Commented Aug 18, 2011 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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