I try to insert programmaticly wordpress posts via cron job.
I have set up many DB Connections
$DB = array(
'naruto' => new wpdb('ultimate_naruto','','ultimate_naruto','localhost'),
'4k' => new wpdb('ultimate_4k','','ultimate_4k','localhost'),
'weihnachten' => new wpdb('ultimate_xmas','','ultimate_xmas','localhost'),
'halloween' => new wpdb('ultimate_hallow','','ultimate_hallow','localhost'),
'disney' => new wpdb('ultimate_disney','','ultimate_disney','localhost'),
'starwars' => new wpdb('ultimate_starwar','','ultimate_starwars','localhost'),
'fossil' => new wpdb('ultimate_fossil','','ultimate_fossil','localhost'),
'avocado' => new wpdb('ultimate_avocado','','ultimate_avocado','localhost'),
'3d-drucker' => new wpdb('ultimate_3d','','ultimate_3d','localhost'),
'lego' => new wpdb('ultimate_lego','','ultimate_lego','localhost'),
'barbie' => new wpdb('ultimate_barbie','','ultimate_barbie','localhost')
);
And want to insert after some DataOperations to insert into corresponding Database, i think i have the connections setup rigth but since wp_insert_post is not part of the class wpdb /global $wpdb it is not working... i couldn´t find a way to select the right database to perform wp_insert_post right.
foreach($arr_keywords as $portal => $keywords){
foreach($keywords as $keyword){
if(stripos($_title,$keyword) !== false){
$row = $DB[$portal]->get_results("SELECT COUNT(*) FROM wp_posts WHERE id='$id'");
if($row == 0){
$data = prepare_data($id,$arr_portal[$portal]);
//do something to select correct db here
wp_insert_post($data);
}
}
}
}
can anybody help?
Thanks