Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gotta be a better way to get an array of Child Page IDs than this. WordPress
// 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