WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
Another alternative is using get_posts() with post_type and numberposts parameters. – Michal Mau Aug 17 '11 at 15:46
@Maugly Why not add this as an answer? – kaiser Aug 17 '11 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 Aug 18 '11 at 9:22

Your Answer


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.