我有以下查询,将我所有在“帖子”上匹配的子弹移动到自定义帖子类型:
UPDATE `wp_posts` p
LEFT OUTER JOIN wp_term_relationships r ON r.object_id = p.ID
LEFT OUTER JOIN wp_term_taxonomy x ON x.term_taxonomy_id = r.term_taxonomy_id
LEFT OUTER JOIN wp_terms t ON t.term_id = x.term_id
SET p.post_type = 'recipe'
WHERE p.post_type = 'post' AND x.taxonomy = 'category'
AND t.slug = 'cocktails'
OR t.slug = 'breakfast'
OR t.slug = 'cookies-recipes'
OR t.slug = 'desserts'
OR t.slug = 'main-course'
OR t.slug = 'sides'
OR t.slug = 'soups'
OR t.slug = 'starters'
问题是,AND x.taxonomy='category'
对我不起作用,它会将与“类别”和“ post_tag”相关联的所有子弹都移动了,我如何才能使其仅在寻找“类别”的地方使用呢?只是移到那儿?
答案 0 :(得分:-1)
也许您正在寻找类似这样的东西...
UPDATE wp_posts p
JOIN wp_term_relationships r
ON r.object_id = p.ID
JOIN wp_term_taxonomy x
ON x.term_taxonomy_id = r.term_taxonomy_id
JOIN wp_terms t
ON t.term_id = x.term_id
SET p.post_type = 'recipe'
WHERE p.post_type = 'post'
AND x.taxonomy = 'category'
AND t.slug IN('cocktails',
'breakfast',
'cookies-recipes',
'desserts',
'main-course',
'sides',
'soups',
'starters')
有关更多帮助,请参见:Why should I provide an MCRE for what seems to me to be a very simple SQL query?