Thread Starter
ikramy
(@ikramy)
Thanks for the answer, but what I really wanted is to list all the 3rd level pages rather than listing the pages of parent ID 3.
Maybe the long road there but try:
<?php
$gen1 = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent = 0 AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
$gen1_ids = implode($gen1,', ');
$gen2 = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN ($gen1_ids) AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
$gen2_ids = implode($gen2,', ');
$gen3 = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN ($gen2_ids) AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
$gen3_ids = implode($gen3,', ');
wp_list_pages('include=' . $gen3_ids . '&title_li=<h2>' . __('Level 3 Pages') . '</h2>');
?>
The nested queries approach above seems like a good route– probably better than using nested foreach statements and only outputting the third iteration of wp_list_pages(“child_of=$previousgen”).
Thread Starter
ikramy
(@ikramy)
Thanks guys, I also tried this, and it works
<?php
$string = wp_list_pages('title_li&echo=0');
if (preg_match('#^.*?<ul>.*?<ul>.*?(\s*<ul>.*?</ul>)#is', $string, $matches))
{
echo $matches[1]."\n";
}
?>