You already have your updateYoutube()
function. Edit it to insert a new post. Very generally:
function updateYoutube( $videocode ){
global $conn;
$run = $conn->query("SELECT `ID` FROM `youtubetable` WHERE `ID` = '$videocode'");
if ($run->num_rows > 0)
return false;
else
{
if ($conn->query("INSERT INTO youtubetable (`ID`) VALUES ('$videocode')") === TRUE) {
// #################################
// NOTE: The following 99% cribbed from the wp_insert_post() entry in the Codex
// Create post object
$my_post = array(
'post_title' => 'My post',
'post_content' => $videocode,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(8,39) // Obviously illustrative only
);
// Insert the post into the database
wp_insert_post( $my_post );
// ##################################
return true;
} else {
return false;
}
}
}
The auto-embedding system should, I believe, take care of the rest, though I have not tested it.