Skip to content

Instantly share code, notes, and snippets.

@chuckreynolds
Created February 5, 2019 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chuckreynolds/25def76a6357941422d916a801383fb4 to your computer and use it in GitHub Desktop.
Save chuckreynolds/25def76a6357941422d916a801383fb4 to your computer and use it in GitHub Desktop.
Gotta be a better way to get an array of Child Page IDs than this. WordPress
<?php
// basic idea here is a common function to pass a parent page ID
// and get back an array of it and its child page IDs only
function getChildPageIDs( $id ) {
$child_pages = get_pages('child_of='.$id);
$ids_to_remove = array($id); // we want to remove parent id too
foreach($child_pages as $child) {
array_push($ids_to_remove,$child->ID); // for every child add the id into array
}
return $ids_to_remove; // send it all back
}
return getChildPageIDs( '123' );
// there's gotta be a better way to do this no?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment