0

I have created custom post type. I have posted a parent post and it has a few child posts as well.

On the Parent post, I want to show its children posts.

How can I achieve it?

1 Answer 1

1

This would do it..

function get_child_pages() {
    global $post;
    $query = new WP_Query( array( 'post_parent' => $post->ID ) );

    if ( $query->have_posts() ) {
        echo '<ul>';
    while ( $query->have_posts() ) {
        $query->the_post();
            //Child pages
            echo '<li>' . get_the_title() . '</li>';
    }
        echo '</ul>';
    } else {
     echo 'Sorry, No posts found.';
    wp_reset_postdata();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.