Display child post on parent post page in wordpress


Staff member
Our current website is using custom posts with parent/child posts.
When viewing a (parent) post, a plugin is used to pull its child posts and those are displayed in a tab on the page.

We are using a new version of that custom theme on several websites now and are no longer using parent/child relationship. Instead we have metaboxes in our custom posts types and all additional information can be filed right there.

I wanted to update this particular website with the latest version of the theme, but since it's using parent/child relationship I wanted to add a few lines of code to the theme in order to achieve the same result and keep the old posts the way they are instead of modifying them all.

Here's what I want to do : I want a very simple way to display all child post (in order) on a parent post page.

I've found a few ideas here and there but none seems to be working so far. (Here's one for example : <a href="http://www.wpbeginner.com/wp-tutori...f-child-pages-for-a-parent-page-in-wordpress/" rel="nofollow noreferrer">http://www.wpbeginner.com/wp-tutori...f-child-pages-for-a-parent-page-in-wordpress/</a> as well as this one <a href="https://wordpress.stackexchange.com...-list-of-child-pages-with-parent-in-wordpress">https://wordpress.stackexchange.com...-list-of-child-pages-with-parent-in-wordpress</a>). I don't know if it has to do with the fact that i'm using post rather than pages.

I don't want a list of the child post but rather display the content of those directly. Was thinking the best way to achieve this might be to create a function to retrieve the child post and then echoing the result in the template. That way without having to change our theme it could work with our different website.

<strong>EDIT :</strong>

So far here's what i've tried within single.php :

$query = new WP_Query( array( 
    'post_parent' =&gt; get_the_ID(),
while($query-&gt;have_posts()) {
    the_content(); //Outputs child's content as it is


I then changed the code to :

$new_args = array(
'order'          =&gt; 'ASC',
'post_parent'    =&gt; get_the_ID()
$new_query = new WP_Query( $new_args);
if ($new_query-&gt;have_posts() ) {
    while($new_query-&gt;have_posts() ) {


and then since it didn't work either i've changed it to :

$children = get_children( array('post_parent' =&gt; get_the_ID()) );
foreach ( $children as $children_id =&gt; $children ) {

The latest seems to be able to return some results, it "knows" that the current post has children in it but i'm displaying the title and content of the current post. I'm pretty sure I shouldn't be using
in here.