[resolved] Get direct successor of given ID (3 posts)

  1. anve
    Posted 4 years ago #


    I want to get the direct successor of a page. E.g.

    [3] Products
    ----[7] Steel
    ------[12] Nails
    ------[14] Miscellaneous
    ----[8] Plastic
    ----[9] Other

    I want the child pages of products. So I would get steel, plastic and other. How do I do that?

    I tried this:

    $my_wp_query = new WP_Query();
    $all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
    $res = get_page_children($currentPageID, $all_wp_pages);

    This gives me also nails and miscellaneous. But I don't want these two. I also tried

    $args = array('numberposts' => '25', 'post_type' => 'page', 'post_status' => 'publish');
    $res = get_page_children($currentPageID, get_posts($args));

    Same result. I also tried with

    $args = array('numberposts' => '25', 'post_type' => 'page', 'post_status' => 'publish');
    $res = get_page_hierarchy( get_posts($args), $currentPageID );

    Same result.

    Even this code doesn't change anything:

    $args = array('child_of' => $currentPageID);
    $res = get_pages($args);

    How do I get the direct successor of the given ID? Not the successor of the successor ..

  2. Fire Truck
    Posted 4 years ago #

    Try this function:

    function &my_get_page_children($page_id, $pages) {
        $page_list = array();
        foreach ( (array) $pages as $page ) {
            if ( $page->post_parent == $page_id ) {
                $page_list[] = $page;
        return $page_list;
  3. anve
    Posted 4 years ago #

    Thanks Fire Truck. In the meantime I came up with the same function you wrote but thanks for posting it anyway!

Topic Closed

This topic has been closed to new replies.

About this Topic