問題描述
我嘗試了匯入工具,似乎對不同的表做了不同的事情。
對於 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 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。