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

How can I limit the get_pages to only show 5 items?

I thought adding 'number' => 5 to the array would limit it to 5 but it doesn't show anything. Here's my code:

$pages = get_pages(array('post_type' => 'page','sort_column' => 'menu_order','sort_order' => 'ASC','child_of' => 765));

foreach($pages as $post)
$fields = get_fields();
        <p><?php echo $fields->start_date; ?> <a href="<?php echo get_page_link($post->ID) ?>"><?php echo substr($fields->event_title,0,24) . "..."; ?></a></p>

share|improve this question
is it possible that you had a typing error or got the syntax wrong? unfortunately your posted code does not show your trial. – Michael May 26 '11 at 11:34
Syntax all correct, seems there's a bit of a problem with it. Get_children seemed to work though. – Rob May 26 '11 at 12:08
up vote 2 down vote accepted

I have had similar problems with the number attribute in get_pages()

I got around it by using get_children:

$pages = get_children(array(
   'numberposts' =>1,
   'post_parent' => $heading_page->post_id

and using post_parent instead of child_of.

share|improve this answer
That worked, thanks. Get_pages just would not work whichever way I did it! – Rob May 26 '11 at 12:07
I've never actually posted a bug report for wordpress but this seems like a likely candidate allright – edzillion May 26 '11 at 12:37
Yep definitely! All the suggestions from other people don't seem to work and I've had trouble with it before. – Rob May 26 '11 at 13: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.