首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何重新定位图像

如何重新定位图像
EN

WordPress Development用户
提问于 2016-04-15 13:44:38
回答 1查看 36关注 0票数 0

我需要将附加到特定类别(MyCat)的所有图片从当前的标准位置(/上载/年/月/)移到特定的类别文件夹(/上载/mycat/)。

例如:

代码语言:javascript
复制
/uploads/2015/06/mycat-post1-image1.jpg
/uploads/2015/06/mycat-post1-image2.jpg
/uploads/2015/07/mycat-post2-image3.jpg
/uploads/2015/08/mycat-post3-image4.jpg

..。还有更多我的猫图像..。

搬到..。

代码语言:javascript
复制
/uploads/mycat/image1.jpg
/uploads/mycat/image2.jpg
/uploads/mycat/image3.jpg
/uploads/mycat/image4.jpg

(没有必要重新命名,只是为了说明)。

我需要物理地将图像从源文件夹移到目标文件夹,还需要更改数据库中的链接。但是,怎么做呢?

EN

回答 1

WordPress Development用户

回答已采纳

发布于 2016-04-20 22:50:19

我不得不编写一个外部程序,我看不到任何其他方法。我在我的例子中使用了。

查询:

代码语言:javascript
复制
SELECT p.post_title, m.meta_value
FROM wp_term_taxonomy tt
INNER JOIN wp_term_relationships tr on tt.term_taxonomy_id = tr.term_taxonomy_id
inner join wp_posts p on p.ID = tr.object_id
inner join wp_posts p2 on p.ID = p2.post_parent
inner join wp_postmeta m on p2.ID = m.post_id
where tt.term_id = 795
and p.post_status = 'publish'
and p.post_type = 'post'
and p2.post_type='attachment' and p2.post_status = 'inherit'
and m.meta_key = '_wp_attached_file'

但是无法复制到特定的mycat,wordpress不识别媒体的自定义文件夹结构。

然后,由于所有图片都在本年度/月份,我做了:

代码语言:javascript
复制
UPDATE wp_posts p
SET p.post_content = REPLACE(p.post_content, 'http://miwp.local/wp-content/uploads/2014/02/', 'http://miwp.local/wp-content/uploads/2016/04/'),
p.post_content = REPLACE(p.post_content, 'http://miwp.local/wp-content/uploads/2014/03/', 'http://miwp.local/wp-content/uploads/2016/04/'),
p.post_content = REPLACE(p.post_content, 'http://miwp.local/wp-content/uploads/2014/04/', 'http://miwp.local/wp-content/uploads/2016/04/'),
p.post_content = REPLACE(p.post_content, 'http://miwp.local/wp-content/uploads/2014/05/', 'http://miwp.local/wp-content/uploads/2016/04/'),
p.post_content = REPLACE(p.post_content, 'http://miwp.local/wp-content/uploads/2014/06/', 'http://miwp.local/wp-content/uploads/2016/04/'),
p.post_content = REPLACE(p.post_content, 'http://miwp.local/wp-content/uploads/2014/07/', 'http://miwp.local/wp-content/uploads/2016/04/'),
p.post_content = REPLACE(p.post_content, 'http://miwp.local/wp-content/uploads/2014/08/', 'http://miwp.local/wp-content/uploads/2016/04/'),
p.post_content = REPLACE(p.post_content, 'http://miwp.local/wp-content/uploads/2014/09/', 'http://miwp.local/wp-content/uploads/2016/04/')
WHERE p.post_name LIKE 'mycat-%';

如果post_name的前缀是'mycat-‘。

票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/223792

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档