I need to create wordpress posts using wp_insert_post, and fill "post_title" and "post_content" with values queried from an external (not wordpress) database. No matter what I try, I still get the same error.
Wordpress Database Error: database_name.wp_phppc_functions' doesn't exist]
SELECT * FROM `wp_phppc_functions` WHERE `id` = 31
I have tried the following code as a plugin, inserting into functions.php and as a standalone file but I get the same error. For some reason, the site still thinks it is in the other database? Any help you can give me would be much appreciated!
$conzz = mysql_connect("localhost","username","password");
if (!$conzz) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database_name", $conzz);
$resultzz = mysql_query("SELECT T1.ID, REBATE_CODE, LONG_DESC, INCENT_TECH_ID, UPGRADE_TECH FROM T_L_INCENTIVES T1 INNER JOIN T_L_INCENT_TECH T2 ON T1.L_INCENT_TECH = T2.ID INNER JOIN T_LIGHTING_TYPE T3 ON T2.E_LIGHTING_TYPE_ID = T3.ID");
while($row = mysql_fetch_array($resultzz)) {
$new_post = array(
'post_title' => $row['REBATE_CODE'] ,
'post_content' => $row['LONG_DESC'] ,
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(10)
);
$conzzz = mysql_connect("localhost","username","password","wordpress_database");
if (!$conzzz) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("wordpress_database", $conzzz);
wp_insert_post( $new_post );
}
?>