Skip to content

Instantly share code, notes, and snippets.

@sivel
Created April 9, 2009 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivel/92659 to your computer and use it in GitHub Desktop.
Save sivel/92659 to your computer and use it in GitHub Desktop.
<?php
add_filter('wp_list_pages_excludes', 'remove_others_children');
function remove_others_children($excludes = array()) {
$all_pages = get_pages();
$all_children = (array) get_page_children(true, $all_pages);
foreach ( $all_children as $child )
$excludes[] = $child->ID;
if ( ! is_page() )
return $excludes;
global $post;
$this_heirarchy = (array) $post->ancestors;
$this_children = (array) get_page_children($post->ID, $all_pages);
foreach ( $this_heirarchy as $ancestor )
$this_children = array_merge($this_children, (array) get_page_children($ancestor, $all_pages));
foreach ($this_children as $child)
$this_heirarchy[] = $child->ID;
return array_diff($excludes, $this_heirarchy);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment