I'm working on a site that has several hundred pdf files uploaded over the course of a few months. All uploads are organised in the uploads directory by year/month.
The client has just decided they don't want dates in their pdf urls. Instead of having the URL
site.com/app/uploads/2019/06/whatever.pdf they want the url
site.com/app/uploads/pdf/whatever.pdf. Note that this only applies for pdf files.
For new uploads this is easy enough. I added a filter for
wp_handle_upload_prefilter that checks if the extension is pdf and changes the upload directory to
uploads/pdf accordingly. However I'm not sure how to change the URL for all existing pdfs.
I looked into moving all pdfs into the
uploads/pdf directory and then modifying the
wp_posts GUID field to reflect the new location with
guid = CONCAT(
SUBSTRING_INDEX(guid, '/uploads', 1),
SUBSTRING_INDEX(guid, '/', -1)
post_mime_type = 'application/pdf'
..but this didn't work. (done on a test site). The GUIDs were changed but the URLs remained the same.
How can I update the URLs of all pdf uploads without modifying URLs of any other upload type?