WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to check if page is child of some exact page? (4 posts)

  1. kkarpieszuk
    Member
    Posted 4 years ago #

    Hello. Imagine that pages with id 3, 4, 5 are childs of page with id 1

    How to check if for example page id=3 is child of id=1?

    I am creating some plugin which on load of page should check if page is child of page id=1 and if yes, do something.

    I know that i can use $wpdb and check it directly in database but maybe wordpress has some conditional tag or some function for this?

  2. MichaelH
    Member
    Posted 4 years ago #

    In a post loop, it could be as simple as something like this:

    <?php
    if (283 == $post->post_parent) {
    echo 'this post has a parent of 283';
    }
    ?>
  3. kkarpieszuk
    Member
    Posted 4 years ago #

    thank you very much :)

  4. chizet
    Member
    Posted 3 years ago #

    Thanks MichaelH. Exactly what I was looking for as well.

Topic Closed

This topic has been closed to new replies.

About this Topic