admin管理员组

文章数量:1323702

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?

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?

Share Improve this question asked Sep 8, 2020 at 12:05 PaulJPaulJ 1581 silver badge7 bronze badges 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
Add a comment  | 

2 Answers 2

Reset to default 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.

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.

本文标签: postsReinstall Wordpress while keeping attachments