As I originally suspected, menu-item-parent-id
takes the id of the menu item and not the id of the parent page.
So I referenced the menu item ID and passed it into the recursive function :
function buildMenu( $array, $menu_id, $parent_id = false ) {
foreach ($array as $menu) {
$menuItemId = wp_update_nav_menu_item(
$menu_id,
0,
array(
'menu-item-title' => $menu[0]->post_title,
'menu-item-object' => 'page',
'menu-item-object-id' => $menu[0]->ID,
'menu-item-type' => 'post_type',
'menu-item-status' => 'publish',
'menu-item-parent-id' => $parent_id
)
);
if(!empty($menu[1])) {
buildMenu( $menu[1], $menu_id, $menuItemId );
}
}
}