Limit get_pages to only show 5 items

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:

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

foreach($pages as $post)
{
setup_postdata($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>
<?php
}

wp_reset_query();
?>

Related posts

Leave a Reply

1 comment

  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.