{"id":29912,"date":"2022-02-04T10:34:51","date_gmt":"2022-02-04T10:34:51","guid":{"rendered":"https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/"},"modified":"2024-07-03T06:08:15","modified_gmt":"2024-07-03T06:08:15","slug":"sql-query-to-delete-entire-woocommerce-products-in-one-hit","status":"publish","type":"knowledgebase","link":"https:\/\/www.wpstaq.com\/sg\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/","title":{"rendered":"SQL query to delete entire WooCommerce products in one hit"},"content":{"rendered":"<p>If you have a sizeable product list in WooCommerce of say min. 300 products but for some reason you have to delete the entire list, unfortunately WordPress is very limited and slow when it comes to deleting the data. Typically, deleting anything beyond 500 products may show a 503 or 504 gateway error.<\/p>\n<p>Imagine if you had 7,000 products to delete; you would probably go bald before you could even finish the job!<\/p>\n<p>But there&#8217;s another way and it&#8217;ll take seconds to complete the execution.<\/p>\n<h2>Take a backup of your database<\/h2>\n<p>Firstly, before we execute any SQL query, it is recommended that you take a backup of your database.<\/p>\n<p>We recommend that you take a backup from the Staq interface. You can run a <a href=\"https:\/\/www.wpstaq.com\/knowledgebase\/creating-backups\" target=\"_blank\" rel=\"noopener\"><strong>Manual Backup<\/strong> by following thes instructions.<\/a><\/p>\n<p>Once you&#8217;ve completed a manual backup, please follow the steps below.<\/p>\n<h2>Install WP phpMyAdmin<\/h2>\n<p>The next step is to install a plugin inside your WordPress website.<\/p>\n<p>We recommend that you <a href=\"https:\/\/www.wpstaq.com\/knowledgebase\/access-to-phpmyadmin\" target=\"_blank\" rel=\"noopener\">install WP phpMyAdmin by following these instructions<\/a>.<\/p>\n<h2>SQL Query<\/h2>\n<p>Once you&#8217;ve installed WP phpMyAdmin, click the following:<\/p>\n<ul>\n<li>go to the *_posts table on the left hand side. In the example below, it&#8217;s rfw_posts,<\/li>\n<li>followed by clicking <strong>SQL<\/strong>:<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-6789\" src=\"https:\/\/www.wpstaq.com\/wp-content\/uploads\/2022\/02\/sql-screen-1024x434.png\" alt=\"\" width=\"1024\" height=\"434\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Then, delete the prefilled information and copy and paste this code <strong>(NOTE: if your database prefix is not the default\u00a0<code>wp_<\/code>, you will need to replace this with the database prefix you are using)<\/strong>:<\/p>\n<p><code>DELETE relations.*, taxes.*, terms.*<br \/>\nFROM wp_term_relationships AS relations<br \/>\nINNER JOIN wp_term_taxonomy AS taxes<br \/>\nON relations.term_taxonomy_id=taxes.term_taxonomy_id<br \/>\nINNER JOIN wp_terms AS terms<br \/>\nON taxes.term_id=terms.term_id<br \/>\nWHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product');<\/code><\/p>\n<p><code>DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');<br \/>\nDELETE FROM wp_posts WHERE post_type = 'product';<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-6795\" src=\"https:\/\/www.wpstaq.com\/wp-content\/uploads\/2022\/02\/sql-query-1024x525.png\" alt=\"\" width=\"1024\" height=\"525\" \/><\/p>\n<p>Then, click <strong>GO.\u00a0<\/strong>If successful, you should see something like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-6802\" src=\"https:\/\/www.wpstaq.com\/wp-content\/uploads\/2022\/02\/sql-result-1024x431.png\" alt=\"\" width=\"1024\" height=\"431\" \/><\/p>\n<p>Go back to the WordPress backend and click <strong>Products<\/strong> and you should see that the product lists should be empty. Voil\u00e0!<\/p>\n","protected":false},"featured_media":29629,"parent":0,"template":"","class_list":["post-29912","knowledgebase","type-knowledgebase","status-publish","has-post-thumbnail","hentry","categories-database"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL query to delete entire WooCommerce products in one hit - Managed Hosting Platform for WordPress<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL query to delete entire WooCommerce products in one hit - Managed Hosting Platform for WordPress\" \/>\n<meta property=\"og:description\" content=\"If you have a sizeable product list in WooCommerce of say min. 300 products but for some reason you have to delete the entire list, unfortunately WordPress is very limited and slow when it comes to deleting the data. Typically, deleting anything beyond 500 products may show a 503 or 504 gateway error. Imagine if&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/\" \/>\n<meta property=\"og:site_name\" content=\"Managed Hosting Platform for WordPress\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/staqhosting\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-03T06:08:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wpstaq.com\/wp-content\/uploads\/2023\/05\/allowed-file-types.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.wpstaq.com\\\/knowledgebase\\\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\\\/\",\"url\":\"https:\\\/\\\/www.wpstaq.com\\\/knowledgebase\\\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\\\/\",\"name\":\"SQL query to delete entire WooCommerce products in one hit - Managed Hosting Platform for WordPress\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wpstaq.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.wpstaq.com\\\/knowledgebase\\\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.wpstaq.com\\\/knowledgebase\\\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.wpstaq.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/allowed-file-types.png\",\"datePublished\":\"2022-02-04T10:34:51+00:00\",\"dateModified\":\"2024-07-03T06:08:15+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.wpstaq.com\\\/knowledgebase\\\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\\\/#breadcrumb\"},\"inLanguage\":\"en-sg\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.wpstaq.com\\\/knowledgebase\\\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-sg\",\"@id\":\"https:\\\/\\\/www.wpstaq.com\\\/knowledgebase\\\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.wpstaq.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/allowed-file-types.png\",\"contentUrl\":\"https:\\\/\\\/www.wpstaq.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/allowed-file-types.png\",\"width\":1000,\"height\":500},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.wpstaq.com\\\/knowledgebase\\\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.wpstaq.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL query to delete entire WooCommerce products in one hit\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.wpstaq.com\\\/#website\",\"url\":\"https:\\\/\\\/www.wpstaq.com\\\/\",\"name\":\"Managed Hosting Platform for WordPress\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.wpstaq.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.wpstaq.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-sg\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.wpstaq.com\\\/#organization\",\"name\":\"Staq\",\"alternateName\":\"WPStaq\",\"url\":\"https:\\\/\\\/www.wpstaq.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-sg\",\"@id\":\"https:\\\/\\\/www.wpstaq.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.wpstaq.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/cropped-LogoNoText.png\",\"contentUrl\":\"https:\\\/\\\/www.wpstaq.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/cropped-LogoNoText.png\",\"width\":512,\"height\":512,\"caption\":\"Staq\"},\"image\":{\"@id\":\"https:\\\/\\\/www.wpstaq.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/staqhosting\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/wpstaq\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL query to delete entire WooCommerce products in one hit - Managed Hosting Platform for WordPress","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/","og_locale":"en_US","og_type":"article","og_title":"SQL query to delete entire WooCommerce products in one hit - Managed Hosting Platform for WordPress","og_description":"If you have a sizeable product list in WooCommerce of say min. 300 products but for some reason you have to delete the entire list, unfortunately WordPress is very limited and slow when it comes to deleting the data. Typically, deleting anything beyond 500 products may show a 503 or 504 gateway error. Imagine if&hellip;","og_url":"https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/","og_site_name":"Managed Hosting Platform for WordPress","article_publisher":"https:\/\/www.facebook.com\/staqhosting\/","article_modified_time":"2024-07-03T06:08:15+00:00","og_image":[{"width":1000,"height":500,"url":"https:\/\/www.wpstaq.com\/wp-content\/uploads\/2023\/05\/allowed-file-types.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/","url":"https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/","name":"SQL query to delete entire WooCommerce products in one hit - Managed Hosting Platform for WordPress","isPartOf":{"@id":"https:\/\/www.wpstaq.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/#primaryimage"},"image":{"@id":"https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wpstaq.com\/wp-content\/uploads\/2023\/05\/allowed-file-types.png","datePublished":"2022-02-04T10:34:51+00:00","dateModified":"2024-07-03T06:08:15+00:00","breadcrumb":{"@id":"https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/#breadcrumb"},"inLanguage":"en-sg","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/"]}]},{"@type":"ImageObject","inLanguage":"en-sg","@id":"https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/#primaryimage","url":"https:\/\/www.wpstaq.com\/wp-content\/uploads\/2023\/05\/allowed-file-types.png","contentUrl":"https:\/\/www.wpstaq.com\/wp-content\/uploads\/2023\/05\/allowed-file-types.png","width":1000,"height":500},{"@type":"BreadcrumbList","@id":"https:\/\/www.wpstaq.com\/knowledgebase\/sql-query-to-delete-entire-woocommerce-products-in-one-hit\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.wpstaq.com\/"},{"@type":"ListItem","position":2,"name":"SQL query to delete entire WooCommerce products in one hit"}]},{"@type":"WebSite","@id":"https:\/\/www.wpstaq.com\/#website","url":"https:\/\/www.wpstaq.com\/","name":"Managed Hosting Platform for WordPress","description":"","publisher":{"@id":"https:\/\/www.wpstaq.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wpstaq.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-sg"},{"@type":"Organization","@id":"https:\/\/www.wpstaq.com\/#organization","name":"Staq","alternateName":"WPStaq","url":"https:\/\/www.wpstaq.com\/","logo":{"@type":"ImageObject","inLanguage":"en-sg","@id":"https:\/\/www.wpstaq.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.wpstaq.com\/wp-content\/uploads\/2023\/05\/cropped-LogoNoText.png","contentUrl":"https:\/\/www.wpstaq.com\/wp-content\/uploads\/2023\/05\/cropped-LogoNoText.png","width":512,"height":512,"caption":"Staq"},"image":{"@id":"https:\/\/www.wpstaq.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/staqhosting\/","https:\/\/www.linkedin.com\/company\/wpstaq"]}]}},"_links":{"self":[{"href":"https:\/\/www.wpstaq.com\/sg\/wp-json\/wp\/v2\/knowledgebase\/29912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wpstaq.com\/sg\/wp-json\/wp\/v2\/knowledgebase"}],"about":[{"href":"https:\/\/www.wpstaq.com\/sg\/wp-json\/wp\/v2\/types\/knowledgebase"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wpstaq.com\/sg\/wp-json\/wp\/v2\/media\/29629"}],"wp:attachment":[{"href":"https:\/\/www.wpstaq.com\/sg\/wp-json\/wp\/v2\/media?parent=29912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}