1

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();
?>
2
  • is it possible that you had a typing error or got the syntax wrong? unfortunately your posted code does not show your trial.
    – Michael
    Commented 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
    Commented May 26, 2011 at 12:08

1 Answer 1

3

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.

3
  • That worked, thanks. Get_pages just would not work whichever way I did it!
    – Rob
    Commented 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
    Commented 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
    Commented 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.