Skip to content

Instantly share code, notes, and snippets.

@jorpdesigns
Created July 13, 2021 19:42
Show Gist options
  • Save jorpdesigns/a25f9862932b2e60026f21021b1b8572 to your computer and use it in GitHub Desktop.
Save jorpdesigns/a25f9862932b2e60026f21021b1b8572 to your computer and use it in GitHub Desktop.
Function for querying sibling pages that share same parent
<?php
function sibling_pages_query() {
$parentPageObject = get_page_by_title( 'Parent Page' ); // Replace with parent page title
$output = '';
if ( $parentPageObject ) {
$subPagesArray = get_pages(
array(
'child_of' => $parentPageObject->ID,
'sort_column' => 'menu_order',
'sort_order' => 'asc'
)
);
foreach( $subPagesArray as $subPage ) {
$output .= '<li><a href="'. get_page_link( $subPage->ID ) .'">'. $subPage->post_title .'</a></li>';
}
} else {
$output .= '<li>Coming Soon</li>';
}
return '<div class="custom-page-siblings-loop"><ul>'. $output .'</ul></div>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment