I figured it out on how to create post dynamically. I don't know if it's optimal, but it gets the job done.
I put all the necessary info in variables/arrays and added them into a for loop that does the insertion. It goes through the entire xml file, but will stop and break out of the loop if it comes to a post with the same title (I know this probably wont be the best unique identifier), this way it won't create multiple of the same post. once it break it tells the user how many post has been created:
$flag = true;
for($i=0; $i<24; $i++){
if(!get_page_by_title($b[$i]->title, OBJECT, post)){
//check what category it's in.
if(stristr($feedKeywordsArray[$i],"news")){
$category = 3;
}
elseif(stristr($feedKeywordsArray[$i], "live")){
$category =4;
}
elseif(stristr($feedKeywordsArray[$i], "insider")){
$category =5;
}
elseif(stristr($feedKeywordsArray[$i], "local")){
$category =6;
}
elseif(stristr($feedKeywordsArray[$i], "spotlight")){
$category =7;
}
else{
$category=1;
}
$my_post = array(
'post_title' => $b[$i]->title,
'post_content' => $b[$i]->description,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array($category),
'tags_input' => $feedKeywordsArray[$i]
);
// Insert the post into the database.
$post_id = wp_insert_post( $my_post );
echo "<h1> Post: '" . $b[$i]->title . "' added</h1>";
if($post_id>0){
update_field('excerpt', (string)($b[$i]->description), $post_id);
update_field('vamp-thumbnail', (string)($thumbnail[$i]), $post_id);
update_field('vamp-video', str_replace("#autostart=on;", "#autostart=off;hidecompanion=on;autoadv=off;",(string)($a[$i][0])), $post_id);
}
}
else{
$flag = false;
echo "<h2> Coming Out of the for loop after creating " . $i . " successful post(s).</h2>";
break;
}
}
if($flag){
echo "Created all post";
}
?>