Hi, I am trying without success to list in a page the children titles and their children.
Something like:
Programs:
program 1
Sub program1 1
program 2
Sub program2 1
Sub program2 2
Sub program2 3
program 3
Sub program3 1
but instead I am getting:
Programs:
program 1
Sub program1 1
program 2
Sub program2 1
Sub program2 2
Sub program2 3
program 3
Sub program3 1
Sub program1 1
Sub program2 1
Sub program2 2
Sub program2 3
Sub program3 1
meaning that i get the corretly listing at first but then i get the childs all totheger
this my code:
`<?php
// Set up the objects needed
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
// Get the page as an Object
$programs = get_page_by_title('programs');
$program_children = get_page_children($programs->ID, $all_wp_pages);
foreach($program_children as $post) :
echo '<h2 class="title">'.get_the_title().'</h2>';
$program_childrenL2 = get_page_children(get_the_ID(), $all_wp_pages);
foreach($program_childrenL2 as $postL2) :
setup_postdata($postL2);
echo '<h3 class="title">'.$postL2->ID.'</h3>';
endforeach;
endforeach;
?>`