我花了一些时间在数据库中,试图找出如何清除一些已完成的订单数据。以下是我相信将有助于从已完成的woocommerce订单中删除数据的查询。
我的问题更多的是DB查询:
DELETE * FROM wp_post
JOIN wp_postmeta ON wp_post.ID = wp_postmeta.post_id
JOIN wp_woocommerce_order_items ON wp_postmeta.post_id = wp_woocommerce_order_items.order_item_id
JOIN wp_woocommerce_order_itemmeta ON wp_postmeta.post_id = wp_woocommerce_order_itemmeta.order_item_id
WHERE wp_post.post_type = "shop_order"
AND wp_post.post_status = "wc-completed"
运行上述查询时,我得到以下MySQL错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'* FROM wp_post
JOIN wp_postmeta ON wp_post.ID = wp_postmeta.post_id
JOIN wp_wo\' at line 1
我不是吗
JOIN
我的WordPress表是否正确?
这个问题可能更适合stackoverflow,但我想我会先在这里试试。
以下是正确的查询字符串:
DELETE wp_posts, wp_postmeta, wp_woocommerce_order_items, wp_woocommerce_order_itemmeta FROM
JOIN wp_posts.ID = wp_postmeta.post_id,
wp_postmeta.post_id = wp_woocommerce_order_itemmeta.order_item_id,
wp_posts.ID = wp_woocommerce_order_items.order_item_id
WHERE wp_posts.post_type = "shop_order"
AND wp_posts.post_status = "wc-completed"
它修复了wp\\u post而不是wp\\u post,并包含了DELETE和FROM之间的所有表。