Change wordpress image directory with sql

I changed my default Wordpress download directory:

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

I am a little fixated on the correct 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 all FROM wp_postmeta WHERE meta_value LIKE% / files /% /% / WITH / images /

+4
source share
4 answers

To change the entries for 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/

These are basically 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 download path will be fixed for new files, the original path for the media that has already been inserted in the messages still points to the old directory, since the paths are stored in the database.

+3
source

Instead of doing this, WordPress provides the ability to change the download folder using the wp-config.php file.

Basically you set WP_CONTENT_DIR for the server location and WP_CONTENT_URL for the URI based.

0
source

Another option is to use the following settings: update_option ('uploads_use_yearmonth_folders', 0); update_option ('upload_path', 'images');

0
source

I would recommend the WP Migrate DB plugin for this. This is an easy way.

If you are stuck on a hard path, you can either run the query using REPLACE () for each path you want to replace (the function does not allow wildcards) or try something like this .

0
source

All Articles