2014-11-20 115 views
0

我需要一些幫助才能編寫Mysql查詢以僅從某個父類別中刪除Woocommerce產品。該數據庫包含超過20,000個產品。僅從某些類別父ID中刪除woocommerce產品

我發現下面的查詢:

DELETE relations.*, taxes.*, terms.* 
    FROM wp_term_relationships AS relations 
    INNER JOIN wp_term_taxonomy AS taxes 
    ON relations.term_taxonomy_id=taxes.term_taxonomy_id 
    INNER JOIN wp_terms AS terms 
    ON taxes.term_id=terms.term_id 
    WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product') 

我需要wp_term_taxonomy父ID鏈接這個"7447"所以只產品,該父ID匹配將是removed.The結構有3個級別的子類別的自定義字段,這是甚至可能在MySQL?因爲我找不到任何方式將子類別直接與父類別關聯。

請原諒我的問題,但我在MYSQL查詢中並不擅長。關於這一要求沒有任何網上信息。此外,我認爲對於面臨這個問題的未來開發者來說,這將是一件好事。

很多thx!

回答

1

使用SELECT語句像

SELECT relations.*, taxes.*, terms.* 
    FROM wp_term_relationships AS relations 
    INNER JOIN wp_term_taxonomy AS taxes 
    ON relations.term_taxonomy_id=taxes.term_taxonomy_id 
    INNER JOIN wp_terms AS terms 
    ON taxes.term_id=terms.term_id 
    WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product') 
    AND taxes.parent = 7447 <-- Add this extra condition 
+0

您好thx,爲您的awnser和編輯:) im目前正在上傳一個測試數據庫,但我在阿魯巴,互聯網真的很慢:(我認爲這不會涉及parrent內的任何子類別?一個3級的子貓? – 2014-11-20 19:30:43

+0

@CoenPonsen,我不能說沒有看錶結構,但是,上述查詢將只會得到行'(parent_id = 7447)匹配。 – Rahul 2014-11-20 19:33:03

+0

我想我必須寫一個php腳本,我目前正在尋找本地後端功能 – 2014-11-20 19:34:41

相關問題