所以,作为标题,我的问题是我怎么做:
删除所有“缺货”的产品,不仅要隐藏它们,还要从数据库中删除。
我发现以下代码但是它删除了所有产品,而不仅仅是那些缺货的产品:
DELETE p FROM wp_posts p WHERE p.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 tr FROM wp_term_relationships tr INNER JOIN wp_term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.taxonomy != 'link_category' AND tr.object_id NOT IN ( SELECT ID FROM wp_posts );
答案 0 :(得分:3)
产品是自定义帖子类型,您可以通过使用WordPress中的元查询选择此类产品来删除“缺货”产品
但是,如果您想采用SQL查询方式,则以下查询将执行该作业
DELETE p FROM wp_posts p join wp_postmeta pm on p.ID = pm.post_id WHERE p.post_type = 'product' and pm.meta_key='_stock_status' and pm.meta_value='outofstock';
答案 1 :(得分:1)
试试这个:
DELETE p FROM wp_posts p WHERE p.post_type = 'product' and p.id = '$post->ID';
已编辑:
DELETE p FROM wp_posts p join wp_postmeta m on p.ID = m.post_id WHERE p.post_type = 'product' and m.meta_key='_stock' and m.meta_value='0';