• Resolved anve

    (@anve)


    Hi,

    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 ..

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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;
    }

    Thread Starter anve

    (@anve)

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get direct successor of given ID’ is closed to new replies.