WordPress.org

Ready to get started?Download WordPress

Forums

Is there a "If parent of parent post is" flag? (3 posts)

  1. Carbon-12
    Member
    Posted 5 years ago #

    Hey, in the side bar of my children posts I want to have a link that takes the visitor back to the parent page. This is easy on child pages with one parent as I can simply insert:

    <?php if($post->post_parent=="1025"){?>

    However as soon as I get child pages more than one level deep such as:

    Fish > Tropical Fish > Amazon Fish

    Then the above code no longer works because post_parent id is now Tropical Fish rather than Fish.

    How would I get this to work?

  2. Carbon-12
    Member
    Posted 5 years ago #

    Really didn't know this function existed but a friend just emailed me it:

    $ancestors = get_post_ancestors($post);
    if (in_array(11,$ancestors)){
    ...
    }

    with 11 being switched for the grandparent id

  3. Beee
    Member
    Posted 4 years ago #

    kudos.... needed this....

Topic Closed

This topic has been closed to new replies.

About this Topic