Forums

get_pages: a way to get top level ancestor page title? (3 posts)

  1. ADBL
    Member
    Posted 1 year ago #

    For any (grand-)child page, I need to get the top level ancestor page title. Can I do that with get_pages? How?

    Many thanks!

  2. Clicknathan
    Member
    Posted 1 year ago #

    I've been searching for this as well, get_post_ancestor is as close as I've come, but can't figure out how to get the single top level ID / page vs. the array...

  3. alchymyth
    The Sweeper
    Posted 1 year ago #

    top level page ancestor ID:

    <?php echo array_pop(get_post_ancestors($post->ID)); ?>

    top level ancestor page title:

    <?php echo get_page(array_pop(get_post_ancestors($post->ID)))->post_title; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags