• Is there a way to delete all the products without deleting the virtual / downloadable as well? I have search the internet, found a bunch of the same code, ask on stackoverflow but seems no one no how to do this. Is this even possible? A litle help please… thanks in advance!

    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');
     
    DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
    DELETE FROM wp_posts WHERE post_type = 'product';
    DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
    
    delete from <code>wp_termmeta</code>
    where 
    	<code>term_id</code> in ( 
    		SELECT <code>term_id</code>
    		FROM <code>wp_term_taxonomy</code>
    		WHERE <code>taxonomy</code> in ('product_cat', 'product_type', 'product_visibility') 
    	);
    
    delete from <code>wp_terms</code>  
    where 
    	<code>term_id</code> in ( 
    		SELECT <code>term_id</code>
    		FROM <code>wp_term_taxonomy</code>
    		WHERE <code>taxonomy</code> in ('product_cat', 'product_type', 'product_visibility') 
    	);
    	
    DELETE FROM <code>wp_term_taxonomy</code> WHERE <code>taxonomy</code> in ('product_cat', 'product_type', 'product_visibility');
    DELETE meta FROM wp_termmeta meta LEFT JOIN wp_terms terms ON terms.term_id = meta.term_id WHERE terms.term_id IS NULL;
    DELETE FROM wp_woocommerce_attribute_taxonomies;
    DELETE FROM wp_woocommerce_sessions;
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘SQL query delete all products except virtual / download’ is closed to new replies.