Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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();
?>
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

1 Answer 1

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

 
discard

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.