• Hello !

    I’ve been looking for days all over google to find good way to change ULR of files in media library using SQL query, after mooving files to new folder structure.

    I had more than 10 000 files in uploads folder because the structure uploads/year/month wasn’t activated on the website I’m working on, so I rebuild the proper folder organization and move all files.

    I couldn’t find a good answer on how to update database, I made huge SQL script files updating each files URL in database, some people says we have to update the table post_content, other says we have to update postmeta as well, and GUID too but not sure about this…

    I read as well we should use absolute path instead of relative path…. I tried almost everything but nothing works for me.

    So I’m lost and couldn’t find proper queries to get a clean media library.

    Any usefull information about how to proceed ?

    Thank you guys !

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    I highly recommend this plugin: Better Search and Replace. It makes making changes in your WordPress database very easy.

    Hope that helps!

    Arnel C.

    Hello,

    I wanted to follow up on your question in regards to the absolute path versus the relative path. I looked at the post content column in the posts table to double-check on the path, and yes, the absolute path is used to define the location of the content. You can use the Better Search and Replace plugin to very easily identify a pattern and then update it.

    If you have any further questions or comments, please let us know.

    Regards,
    Arnel C.

    Thread Starter rfouquet

    (@rfouquet)

    Well this plugin is not usefull for me, because I will not copy paste 10 000 URLs by hand.

    The only way to do it for me is using SQL files to update directly in database and made bulk update.

    The other plugin that I found usefull is this case is Media File Manager that allow to reorganize uploads folder and update database at the same time, but I have so many files that it times out during loading file list …

    Thread Starter rfouquet

    (@rfouquet)

    Hello, Any Help please ? This make me mad, I can’t fix it …

    I made this test for one picture only :

    UPDATE wp_posts SET guid = REPLACE (guid, ‘uploads/CCI12042016.jpg’, ‘uploads/2016/06/CCI12042016.jpg’);

    UPDATE wp_posts SET post_content = REPLACE (post_content, ‘uploads/CCI12042016.jpg’, ‘uploads/2016/06/CCI12042016.jpg’);

    UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, ‘uploads/CCI12042016.jpg’, ‘uploads/2016/06/CCI12042016.jpg’);

    SQL output is :

    GUID is udpated (1 line)
    post_content is updated (2 lines)
    meta_value is not modified

    But even with this changes in database, I still have broken link with URL ‘uploads/CCI12042016.jpg’ in the media library.

    What else should I do ?

    I’ve just bumped the same issue and found that wp_postmeta has another field for each attachments
    meta key _wp_attachment_metadata and meta_value contains the urls

    • This reply was modified 8 years, 3 months ago by pompos.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Change Attachment URLs in database SQL query’ is closed to new replies.