• I’m try to get a list of all pages that have been assigned a specific template. In this case, the template is: template-individual-project.php

    For some reason, the code is only returning the names of pages that have a template of “template-individual-project.php” BUT ALSO a setting of “no parent.” If the page has a parent assigned, then the page name will not show up in the results. I want the page to show up regardless of whether or not it has a parent assigned.

    $pages = get_pages(
         array(
        'meta_key' => '_wp_page_template',
        'meta_value' => 'template-individual-project.php'
           )
    );
    
    foreach($pages as $page){
        echo $page->post_title.'<br />';
    }

    Is there an easy way around this?

  • The topic ‘get pages that use specific template – doesn't work if page has parent’ is closed to new replies.