2013-07-09 45 views
0

我正在將一個WP站點遷移到新站點。它們都有很多自定義字段,分類法和帖子類型,所以我不能使用內置的插件來導入/導出。在Wordpress中使用兩個數據庫時,某些函數不起作用

相反,我已經在同一臺服務器上設置了兩個數據庫,並且可以使用$wpdb->select('old_db_name')$wpdb->select(DB_NAME)輕鬆切換它們。我爲此創建了一個小插件,以便它可以在WP中運行,從而允許我使用所有WP方法獲取和插入帖子等。

除了一件事情之外,一切正常;分類。我試過的所有與分類法相關的函數都會查詢DB_NAME數據庫(即WP安裝運行的那個數據庫)。

這裏有一個簡單的例子:

<?php 
global $wpdb; 

# Use default DB 
$wpdb->select(DB_NAME); 

# Prints "2" (I've only added two posts to the new installation) 
echo count(get_posts(array('numberposts' => -1))); 
# Prints all the taxonomies 
var_dump(get_taxonomies()); 

# Switch to old DB 
$wpdb->select('old_db_name'); 

# Prints > "300" (there are roughly 300 posts in the old DB - the number is correct and NOT the same as before) 
echo count(get_posts(array('numberposts' => -1))); 
# Prints EXACTLY the same thing as the previous call, even though the old DB has different custom taxonomies 
var_dump(get_taxonomies()); 

wp_get_post_terms()沒有工作,要麼而是查詢新的DB(如果我嘗試獲取來自一個古老的分類,在新的DB WP拋出不再存在的條款一個錯誤說分類不存在)。

這是一個錯誤?任何方式來解決它?沒有太多關於在WP中使用多個數據庫的信息,所以無法在網上找到任何東西。

回答

0

好了經過幾個小時的調查,似乎WP緩存了所有可用的分類標準,因此在切換DB時,不會重新檢查可用的分類標準。它確實然而從正確的數據庫中選擇數據,所以這不是問題。

我想出的解決方案是簡單地將缺失的分類法添加到新的數據庫(暫時),遷移後我將它們刪除。

相關問題