Forums

How to get ancestors with changing ID (2 posts)

  1. kidAlynch
    Member
    Posted 2 years ago #

    So, I am sure this is another simple thing that millions have figured out. But looking through the forums I cant find a perfect fit for what I would like to do.

    I want to generate a list of ancestor pages and their links, but the catch is, I only want the ancestors of the page ID that I am on. I dont want allllll of the ancestors of alllll of the pages.

    If I only have one sidebar then I cant just enter the ID number as '35' or '22' I need to say get all the ancestors of post->ID

    I know this is so simple its on the tip of my tongue. Any helpers?

  2. eddowding
    Member
    Posted 2 years ago #

    $ancestors = get_post_ancestors($post);

    if(in_array(17, $ancestors)) {
    // Code that will be parsed when this page has a ancestor with id 17
    }

Topic Closed

This topic has been closed to new replies.

About this Topic