I dynamically create iterations of a form field with jquery, but they all carry the name extrakosten[] for the first variable and the other variable vergoeding[].
The php:
$postTitle = ''; // save post title
if(isset( $_POST['submit'] )){ // if submit button is present
for ($i=0; $i < count($_POST['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
wp_set_post_terms( $pid, $_POST['extrakosten'],'kostenpost',false);
wp_set_post_terms( $pid, $_POST['vergoeding'],'vergoedingaanleg',false);
} // close for loop
}
What happens now, is that when I click the submit button, a new post under custom post type 'landschapspakket' is made. The values under vergoeding and kostenpost are being posted in the custom taxonomy 'vergoedingaanleg' and 'kostenpost'.
What it does now, is create ONE post with TWO values for 'kostenpost' and 'vergoeding'. What I try to achieve is to create TWO posts, each with ONE value for both 'kostenpost' and 'vergoeding'.
I think something might be wrong with the array. I'm new to arrays. Any suggestions? Thanks for the help