Created
February 5, 2019 11:43
-
-
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
This file contains 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 | |
// 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