You could try something like this:
$postTitle=""; // save post title
if(isset( $_POST['submit'])){ // if submit button is present
$vergoeding=$_POST['vergoeding'];
$extrakosten=$_POST['extrakosten'];
for ($i=0; $i < count($vergoeding); $i++) {
$new_post = array(
'post_title' => $postTitle,
'post_content' => ' ', // can not be empty
'post_status' => 'publish',
'post_type' => 'landschapselement' // custom post type
);
$pid = wp_insert_post($new_post); // insert the post
if(isset($extrakosten[$i]) && $pid > 0){
wp_set_post_terms( $pid, $extrakosten[$i],'kostenpost',false);
}
if(isset($vergoeding[$i]) && $pid > 0){
wp_set_post_terms( $pid, $vergoeding[$i],'vergoedingaanleg',false);
}
} // close for loop
}
It looks like you where inserting an array of terms in each wp_set_post_terms()
.
I try to add a string instead in the above code example.
ps: It is not clear why you use count($vergoeding)
if you want only two inserted posts? So it looks like this array is supposed to include 2 items.