【发布时间】:2014-09-20 06:34:26
【问题描述】:
我尝试通过 cron 作业以编程方式插入 wordpress 帖子。
我已经建立了很多数据库连接
$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')
);
并且想在一些 DataOperations 之后插入以插入相应的数据库,我想我的连接设置是正确的,但是由于 wp_insert_post 不是 wpdb /global $wpdb 类的一部分,所以它不工作......我找不到一种选择正确的数据库来执行 wp_insert_post 的方法。
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);
}
}
}
}
有人可以帮忙吗?
谢谢
【问题讨论】:
-
我可以只使用 SQL 来管理它,但是帖子没有正确创建 -> 没有永久链接等
标签: php wordpress cron multiple-databases