0

I have a Wordpress installation that I want to reinstall. However, I also have in it several uploaded files (.doc and PDFs) that are linked by external sites. They are not used in any of my own pages: I just uploaded them to my Wordpress site instead of putting them in a Dropbox or a Google Drive, and now I can't (or shouldn't) delete them.

The good thing: they are all on the same directory: /wp-content/uploads/2020/07/, so I could just delete everything, reinstall Wordpress and then upload the files to the same directory... However, I don't like the idea of having stray files in my Wordpress installation without WP knowing about them, so I would also like to keep the DB entries that keep track of those files.

If I'm not mistaken, the attachments are kept in the wp_posts table, so what I would have to do is:

  1. Dump all the wp_posts entries referring to the attachments.
  2. Dump all the wp_postmeta entries referring to the entries in wp_posts.
  3. Inserting those entries by hand in the new Wordpress' tables.

Is there anything I'm missing? Any other place in the Wordpress DB where there might be information?

1
  • It might be simpler to just reupload them to the new site, then edit the wp_post and wp_postmeta entries to make sure they're pointing to the old 2020/07 folder.
    – Rup
    Commented Sep 8, 2020 at 12:21

2 Answers 2

1

Depending on how those inbound links work, this could be simpler than you think.

If the links are direct to files in the file system, Wordpress isn't actually needed at all - just a corresponding path for a valid URL.

So let's say you install WP today, the 'earliest' folder in uploads will be 2020/09. If you setup WP as normal and simply copy in the 2020/07 folder from your previous install, the files will be accessible to external visitors as normal. WP will not overwrite that folder as the writing of files is based on upload date (by default). It can't go back in time (without a hack).

The problem comes if their links are to attachment pages, rather than the attachments themselves. In that case, I think the simplest and most manageable option is actually to setup some redirects in htaccess. Then create new attachments in your new WP install and redirect old path to new.

2
  • The links are only to the files, not to any WP page. I hadn't thought about the fact that a new installation won't touch older uploads! Thanks.
    – PaulJ
    Commented Sep 8, 2020 at 17:27
  • Glad it helped! One further thing, if you just reinstall WP into the same location it may leave old files there. So you can just bulk cut/paste the entire install into an archive folder first so you are starting from a clean slate. Then move across what you need.
    – t2pe
    Commented Sep 8, 2020 at 17:34
0

I agree with @t2pe. Moreover, I would consider moving these PDFs and DOCs to independent location. Just like you mentioned: a public folder in Dropbox or Google Drive would do the trick.

Then, create a directory 2020/07 in uploads and from there, in htaccess redirect all traffic to a cloud storage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.