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>

  • 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, 2011 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, 2011 at 12:08

1 Answer 1


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.

  • That worked, thanks. Get_pages just would not work whichever way I did it!
    – Rob
    May 26, 2011 at 12:07
  • I've never actually posted a bug report for wordpress but this seems like a likely candidate allright
    – edzillion
    May 26, 2011 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, 2011 at 13: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.