Created
July 13, 2021 19:42
-
-
Save jorpdesigns/a25f9862932b2e60026f21021b1b8572 to your computer and use it in GitHub Desktop.
Function for querying sibling pages that share same parent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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