sql query to bulk remove woocommerce products by publish date

we have over 50k products on our store site and about half of them need to be deleted. We did a fresh upload of products using wpallimport and set the option to remove any products that were not in the upload but it didn’t work. Instead it just added all of the ones in our csv. We tried doing bulk delete with BulkWP but it crashes the site. I have been manually removing them but can only do 60 at a time to be safe that is doesn’t crash. I have added memory to 1024, execution time to 600, input vars to 3000 but it still does not like it. We would like to delete all products that have a post date older than the last import using a sql query as that will probably be the quickest way but wanted to see if this would work as I have it here with the X being how many days old:

 

Woocommerce products are located mainly in 2 tables, the wp_posts and wp_postmeta. If you want to delete them, you will have to use a JOIN clause to combine the product rows from these tables.

Suppose you want to delete every product added before the 1st of September of 2018. You can use this query below.

DELETE wp_posts, wp_postmeta FROM wp_posts 
JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_posts.post_type = 'product' and wp_posts.post_date < '2018-09-01'

5/5 - (100 bình chọn)

Trả lời

Email của bạn sẽ không được hiển thị công khai.

btn-dangkyhocthu