Title: ONLY display the pages in the 3rd level
Last modified: August 19, 2016

---

# ONLY display the pages in the 3rd level

 *  Resolved [ikramy](https://wordpress.org/support/users/ikramy/)
 * (@ikramy)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/page_list/)
 * Hi,
 * I have 3 levels navigation on my site as the following:
 * — Page 1.1 (level 1)
    — Page 1.2 (level 1) —- Page 1.2.1 (level 2) —- Page 1.2.2(
   level 2) —— Page 1.2.2.1 (level 3) —— Page 1.2.2.2 (level 3) —— Page 1.2.2.3 (
   level 3)
 * What I want on one of my pages is to ONLY display the pages in the 3rd level.
   How can I do that?
 * [title moderated]

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/page_list/#post-1253252)
 * `wp_list_pages('child_of=3')`
 * [http://codex.wordpress.org/Template_Tags/wp_list_pages](http://codex.wordpress.org/Template_Tags/wp_list_pages)
 *  Thread Starter [ikramy](https://wordpress.org/support/users/ikramy/)
 * (@ikramy)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/page_list/#post-1253283)
 * 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.
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/page_list/#post-1253367)
 * 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>');
       ?>
       ```
   
 *  [mtw28](https://wordpress.org/support/users/mtw28/)
 * (@mtw28)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/page_list/#post-1253368)
 * 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](https://wordpress.org/support/users/ikramy/)
 * (@ikramy)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/page_list/#post-1253585)
 * 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";
       }
   
       ?>
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘ONLY display the pages in the 3rd level’ is closed to new replies.

## Tags

 * [meh_code](https://wordpress.org/support/topic-tag/meh_code/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 4 participants
 * Last reply from: [ikramy](https://wordpress.org/support/users/ikramy/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/page_list/#post-1253585)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
