我希望在主要网站上找到并替换某个关键字.
我通常会使用类似的东西
UPDATE wp_posts
SET post_content = REPLACE (post_content, 'Item to replace here', 'Replacement text here');
但是,我不希望更新跨越整个站点,我希望将其限制为仅一个类别.
谁能告诉我如何实现这一目标?
解决方法:
更新:更确切地说,查询应该看起来
UPDATE wp_term_relationships r JOIN wp_posts p
ON r.object_id = p.id JOIN wp_terms t
ON r.term_taxonomy_id = t.term_id JOIN wp_term_taxonomy x
ON r.term_taxonomy_id = x.term_taxonomy_id
SET p.post_content = REPLACE(post_content, 'Item to replace here', 'Replacement text here')
WHERE t.name = 'My Category'
AND x.taxonomy = 'category'
AND x.parent = 0 -- top level category
注意:在更新任何内容之前:
1)您可以通过发布来检查哪些帖子会受到影响
SELECT *
FROM wp_term_relationships r JOIN wp_posts p
ON r.object_id = p.id JOIN wp_terms t
ON r.term_taxonomy_id = t.term_id JOIN wp_term_taxonomy x
ON r.term_taxonomy_id = x.term_taxonomy_id
WHERE t.name = 'My Category'
AND x.taxonomy = 'category'
AND x.parent = 0 -- top level category