Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change wordpress image directory with sql

Tags:

sql

wordpress

I've changed my wordpress default upload directory from:

mysite.com/files/year/month/upload
to
mysite.com/images/upload

I'm a bit stumped on the proper sql syntax to replace /files/year/month/ with /images/.

Using phpmyadmin, I selected the correct db, selected the correct table, and searched/found what needs to be changed using this sql:

SELECT * 
FROM  `wp_postmeta` 
WHERE  `meta_value` 
LIKE  '%/files/%/%/%'

Now I need to REPLACE everything FROM wp_postmeta WHERE meta_value LIKE %/files/%/%/ WITH /images/

like image 813
Dan Avatar asked Oct 06 '22 11:10

Dan


1 Answers

To modify the entries for the uploaded media files you need to run the queries found in this article: http://www.dezzain.com/wordpress-tutorials/how-to-move-wordpress-uploads-path-to-subdomain/

Mainly these two queries:

UPDATE wp_posts SET post_content = REPLACE(post_content,'http://www.domain.com/wp-content/uploads','http://img1.domain.com/uploads')

and:

UPDATE wp_posts SET guid = REPLACE(guid,'http://www.domain.com/wp-content/uploads','http://img1.domain.com/uploads')

The problem with the other answers is that although the upload path will be fixed for new files, the source path for media that has already been inserted into posts is still pointing to the old directory since the paths are stored in the database.

like image 141
AJ Zane Avatar answered Oct 10 '22 03:10

AJ Zane