問題描述
我嘗試了導入工具,似乎對不同的表做了不同的事情。
對於 posts
:如果一個帖子 (或者技術上也是一個帖子),導入文件中的 title
已經存在於數據庫中,它將不被導入。在這種情況下,Wordpress 界面將顯示 「已存在…」 。
對於 postmeta
:將導入數據庫中的所有行。無論該信息是否已經存在 – > 往往會使數據庫膨脹。
我想知道其他表格會發生什麼。如果已經存在,行將被覆蓋,添加 (如 postmeta
) 或拒絕 (如 posts
))
那麼”already present” 如何定義 (post_id
?term_id
?name
)?
最佳解決辦法
how is “already present” defined here anyway (
post_id
?term_id
?name
)?
帖子標題和日期必須匹配才能存在。
WordPress post_exists()
功能用於確定該帖子是否存在。
從插件代碼:
$post_exists = post_exists( $post['post_title'], '', $post['post_date'] );
沒有提供過濾器來更改此行為。
For
posts
: if a post (or page, which technically is a post too)title
from the import file is already present in the database, it won’t be imported. The WordPress interface in this case will indicate that “there already exists…”.
不僅僅是'post'
和'page'
的 post 類型都可以導入。任何定義的職位類型都可以導入。例如,'nav_menu_item'
在導入代碼中的處理方式不同:
if ( 'nav_menu_item' == $post['post_type'] ) {
$this->process_menu_item( $post );
[...]
導入不會在以下情況下創建新的帖子:1. 帖子類型不存在,2. 給定的帖子 ID 已被註冊為導入或 3. 具有相同標題和日期的帖子已存在。
標記為擁有數據庫中不存在的父級的帖子將成為頂級項。這可能是臨時的,因為父項可能尚未導入。
For
postmeta
: all rows from the imported database will be added. Regardless whether that information was already present -> tends to bloat the database.
對於已經存在的帖子,僅當具有相同標題和日期的帖子已存在 (#3 以上) 時才導入新的/更新的帖子,評論和元數據。
添加後期元素的插件代碼如下:
if ( ! isset( $post['postmeta'] ) )
$post['postmeta'] = array();
$post['postmeta'] = apply_filters( 'wp_import_post_meta', $post['postmeta'], $post_id, $post );
// add/update post meta
if ( ! empty( $post['postmeta'] ) ) {
foreach ( $post['postmeta'] as $meta ) {
$key = apply_filters( 'import_post_meta_key', $meta['key'], $post_id, $post );
$value = false;
if ( '_edit_last' == $key ) {
if ( isset( $this->processed_authors[intval($meta['value'])] ) )
$value = $this->processed_authors[intval($meta['value'])];
else
$key = false;
}
if ( $key ) {
// export gets meta straight from the DB so could have a serialized string
if ( ! $value )
$value = maybe_unserialize( $meta['value'] );
add_post_meta( $post_id, $key, $value );
do_action( 'import_post_meta', $post_id, $key, $value );
// if the post has a featured image, take note of this in case of remap
if ( '_thumbnail_id' == $key )
$this->featured_images[$post_id] = (int) $value;
}
}
}
在插入之前使用'wp_import_post_meta'
過濾器調整後期元數據。可以通過返回 empty value(如 0
) 來取消插入。
I wonder what happens for the other tables.
所有上述信息都是通過閲讀插件代碼 (wordpress-importerwordpress-importer.php
) 來收集的,大部分內容都是用英文寫成的。
在此代碼中沒有運行 SQL 查詢。添加到數據庫的所有信息都是通過使用 WordPress 函數完成的。要了解任何表格如何受到影響,請閲讀代碼。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。