Forums

get_pages() with limit (2 posts)

  1. tobbaz
    Member
    Posted 1 year ago #

    Doing this, gives me 8 pages:

    $first_subpage = get_pages(array(
       'child_of' => $heading_page->post_id
    ));

    Doing this, gives me an empty array:

    $first_subpage = get_pages(array(
       'number' => 1,
       'child_of' => $heading_page->post_id
    ));

    Doing this, gives me 1 page:

    $first_subpage = get_pages(array(
       'number' => 2,
       'child_of' => $heading_page->post_id
    ));

    What's the logic behind this?

  2. MichaelH
    Volunteer
    Posted 1 year ago #

    That has something to do with getting the results with a limit, then having to check for the child_of thing.

    Might try Function_Reference/get_children

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

    or

    <?php
    $args=array(
      'post_parent'=> $heading_page->post_id,
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags