Display child posts on single-template.php?

Hi, I have a custom post type (cars)

And in this I have parent and child posts. On the single page of a parent post I would like to show child posts, can anyone help me with the loop for this? I googled but didn’t really find what I am looking for… maybe I just suck at googling.

My current code:

        $args = array(
            'post_type' => 'cars',
            'posts_per_page' => '-1',
            'post_child' => 0
        $the_query = new WP_Query($args);

        if (have_posts()): while ($the_query->have_posts()): $the_query->the_post(); ?>


<?php endwhile; endif; ?>

Did you see this?


It might have something helpful.

1 Like

Just solved it like this:

    $this_page_id = $post->ID;

    $args = array(
        'post_type' => 'bilmarken',
        'post_parent' => $this_page_id
    $the_query = new WP_Query($args);

But thanks anyhow=)

EDIT: nevermind… il have a look at ur link=)

EDIT2: nevermind again… it did work.

Glad you solved it. I’ll add your solution to my library of things I may have to use in the future with WordPress.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.