WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] How to get children ID’s?

[Resolved] How to get children ID’s?

  • I tried several ways, but I am not able to get it working. Is there here someone who can tell me how I can get the ID’s of the children of a parent page? Parent page ID is known.

Viewing 3 replies - 1 through 3 (of 3 total)
  • designsimply
    Member

    @designsimply

    I’m not sure exactly what you’re trying to do with the children IDs, so there may be a simpler function for you, but you can use get_children(); to get a list of children IDs.

    <ul>
    <?php
    global $post;
    $myposts = get_children('post_parent=2');
    foreach($myposts as $post) :
    ?>
    <li><?php echo $post->ID; ?> - <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>

    That worked great, Thanx!

    Hi guys, thanks very much for this approach but, how do I do the same for posts in certain category, “9” for exemple, or named “music” ?

    Here I only can work with a unique fixed post parent.

    I would need to retrieve all the children from a whole category.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] How to get children ID’s?’ is closed to new replies.