我需要将附加到特定类别(MyCat)的所有图片从当前的标准位置(/上载/年/月/)移到特定的类别文件夹(/上载/mycat/)。
例如:
/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..。还有更多我的猫图像..。
搬到..。
/uploads/mycat/image1.jpg
/uploads/mycat/image2.jpg
/uploads/mycat/image3.jpg
/uploads/mycat/image4.jpg(没有必要重新命名,只是为了说明)。
我需要物理地将图像从源文件夹移到目标文件夹,还需要更改数据库中的链接。但是,怎么做呢?
发布于 2016-04-20 22:50:19
我不得不编写一个外部程序,我看不到任何其他方法。我在我的例子中使用了。
查询:
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不识别媒体的自定义文件夹结构。
然后,由于所有图片都在本年度/月份,我做了:
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-‘。
https://wordpress.stackexchange.com/questions/223792
复制相似问题