Skip to content

Instantly share code, notes, and snippets.

@will83
Last active August 29, 2015 14:27
Show Gist options
  • Save will83/694c388a4612ca9c6d56 to your computer and use it in GitHub Desktop.
Save will83/694c388a4612ca9c6d56 to your computer and use it in GitHub Desktop.
Object depth function
function get_object_depth( $object_id, $object_type ){
$ancestors = get_ancestors( $object_id, $object_type );
return count($ancestors);
// 0 => level 1 (first parent)
// 1 => level 2
// ...
}
@will83
Copy link
Author

will83 commented Aug 17, 2015

$object_id
(int or string) (required) The ID of the child object
Default: None
$object_type
(string) (required) The name of the object type (page, hierarchical post type, category, or hierarchical taxonomy) in question
Default: None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment