0

For example, if this were my page structure:

Food
    Vegetables
    Dairy
    Fruits
        Apples
        Bananas
        Kiwis
        Oranges
Sports
    Hockey
    Baseball
    Football
Entertainment
    Movies
    TV
    Podcasts

... and I was on the Oranges page, it would display this:

Food
    Vegetables
    Dairy
    Fruits
        Apples
        Bananas
        Kiwis
        > Oranges
Sports
Entertainment

I'm attempting to use wp_list_pages() and its child_of option, but it appears to only accept an integer rather than array so I can't just pass what is returned of get_ancestors($post->ID, 'page')

1 Answer 1

1

You can get top levels page id with following function

function find_top_level_id( $post_id ) {
   $ancestors = get_post_ancestors( $post_id );

    if ( $ancestors ) {
        return end( $ancestors );
    } else {
        return $post_id;
    }
}

You can use the returned value with wp_list_pages()

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.