Okay. I solved the problem myself. I was not populating the the array of a meta_key the correct way.
Below, you will find a working solution:
$check_post_exists = function( $title ) use ( $wpdb, $postTypeArray ) {
// Get an array of all posts within our custom post type
$posts = $wpdb->get_col( "SELECT post_title FROM {$wpdb->posts} WHERE post_type="{$postTypeArray["custom-post-type"]}" AND post_status="publish"" );
// Check if the passed title exists in array
return in_array( $title, $posts );
};
$i = 0;
$e = 0;
foreach ( $posts() as $post ) {
// If the post exists, skip this post and go to the next one
if ( $check_post_exists( $post["properties/ID"] ) ) {
$e++;
continue;
}
$i++;
// Insert the post into the database
$post["id"] = wp_insert_post( array(
"post_title" => $post["properties/ID"],
"post_type" => $postTypeArray["custom-post-type"],
"post_punktcat" => array( 4 ),
"post_status" => "publish"
));
// Set post category to 4
wp_set_post_terms($post["id"], 4, 'punktcat', false );
$meta = get_post_meta( $post["id"], 'fredningszone_data', true );
$fredningszone_data = array(
"id" => $post["properties/ID"],
"navn" => $post["properties/NAVN"],
"kontaktsted" => $post["properties/Kontaktsted"],
"fredningsperiode" => $post["properties/FREDNINGSP"],
"periode_type" => $post["properties/PeriodeType"],
"lovgivningsgrundlag" => $post["properties/LOVGRUNDLA"],
"bemaerkning" => $post["properties/BEMARKNING"],
"www" => $post["properties/WWW"],
"www2" => $post["properties/WWW2"],
"geometry" => $post["geometry/type"]
);
// Update meta box values
update_post_meta($post["id"], 'fredningszone_data', $fredningszone_data);
//update_post_meta($post["id"], 'fredningszone_data', $post["zoneid"]);
update_post_meta($post["id"], '_location', $post["zoneid"]);
}