Skip to main content
1 of 2
user avatar
user avatar

WordPress - Retrieve a Page if it's a direct descendant of another Page

I have this piece of code that works great: it retrieves a particular page from my WordPress database so I can wrap custom code around it in a template. In the instance below it grabs the page called Showreel:

        <?php
        $page = get_page_by_title('Showreel');
        ?>          
        <?php
             $my_id = $page;
             $post_id = get_post($my_id, ARRAY_A);
             $title = $post_id['post_title'];
             $content = $post_id['post_content'];
        ?>
        <h3><?php echo $title;?></h3>                       
        <?php 
            echo $content
        ?>

However, I have conundrum - I have some pages that do not have unique names. How can I retrieve a page only if it is a direct descendant of a certain parent e.g. I would like to retrieve a page under Showreel called The Ruth Rendell Mysteries. My initial thought was that the code below would work, but it doesn't.

        <?php
        $page = get_page_by_title('Showreel->The Ruth Rendell Mysteries');
        ?>          
Sparrohawx
  • 163
  • 4
  • 11