I’m trying to sort an array alphabetically based on the parent page title. I have a query that retrieves all pages with a specific page template. When outputting the retrieved pages I need to sort them by the title of the parent page and not the title of the retrieved page itself.
What I have so far:
$opnamePages = new WP_Query(array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'DESC',
'meta_key' => '_wp_page_template',
'meta_value' => 'templates/dienst-sub-opname-page.php'
));
if($opnamePages->have_posts()){
echo "<div class='subNavigationDropdown'>";
echo "<div class='dropdown'>";
while($opnamePages->have_posts()){
$opnamePages->the_post();
$parentPage = wp_get_post_parent_id(get_the_ID());
echo "<a href='".get_permalink()."' title='Ga naar ".get_the_title()."'>".get_the_title($parentPage)."</a>";
}
echo "</div>";
echo "</div>";
wp_reset_postdata();
}