我有一个网站,所有帖子都有下载链接。下载链接如下:http://sitename.com/FileID/filename.zip
我想在每个类别的文件名之前添加不同的单词。例如:
对于类别,我想在文件名之前添加一个类别。新链接如下所示:http://sitename.com/FileID/ACategory-filename.zip
对于B类别,我想在filename之前添加BCategory。新链接如下所示:http://sitename.com/FileID/BCategory-filename.zip
我该怎么做?在phpmyadmin中有没有插件或者有什么方法可以做到这一点?
编辑:
我发现此代码仅在我选择的类别中查找和替换:
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 = \'CATEGORY \'
AND x.taxonomy = \'category\'
现在我找不到任何改变的方法
http://sitename.com/FileID/filename.zip
to http://sitename.com/FileID/ACategory-filename.zip
SO网友:CodeMascot
经过长时间的尝试才找到解决方案-
UPDATE wp_posts p
JOIN wp_term_relationships r
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 = CASE
WHEN t.name = \'ACategory\' THEN REPLACE(post_content, \'http://sitename.com/FileID/filename.zip\',
\'http://sitename.com/FileID/ACategory-filename.zip\')
WHEN t.name = \'BCategory\' THEN REPLACE(post_content, \'http://sitename.com/FileID/filename.zip\',
\'http://sitename.com/FileID/BCategory-filename.zip\')
ELSE post_content
END
WHERE x.taxonomy = \'category\'
仔细看,我对您的代码做了一些更改。并特别注意
CASE
我在代码中包含的命令。为每个类别名称添加一个额外的
WHEN t.name = \'Your-Category-Name\' THEN REPLACE(post_content, \'http://sitename.com/FileID/filename.zip\', \'http://sitename.com/FileID/new-filename.zip\')
.
希望这有帮助。
I tested it and it worked perfectly in my system.