WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to get children ID's? (4 posts)

  1. vcsvu
    Member
    Posted 5 years ago #

    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.

  2. designsimply
    Member
    Posted 5 years ago #

    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>
  3. vcsvu
    Member
    Posted 5 years ago #

    That worked great, Thanx!

  4. Dunkkan
    Member
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.