0

TL;DR: How can I control where files get uploaded - in association with a Content Type/Custom Content Type?

I'm building a website for a Rescue. I've got a Pod that's called Dogs. Inside of Dogs, I have

  • Year Rescued
  • Name
  • Flier Image
  • Images

Say I create a dog called Fluffles. Rescued 2018. Flier added and 3 images added.

Currently, those files are uploaded to

  • WP_Uploads\2018\04\03

And if, tomorrow, I upload a file for Fluffles - omg you have to see the cutest picture EVER!!!... it gets uploaded to

  • WP_Uploads\2018\04\04

That's going to leave a trail of files scattered throughout the site..

Can I change it to where those files get uploaded to, say, WP_Uploads\Dogs\2018\Fluffles\? Or, say, Dogs\2018\3\ (3 being the 3rd dog rescued in 2018 - since Fluffles might get his name changed when adopted)

I haven't seen any plugins that allow me to control where files get uploaded - much less in conjuncture with a Pods Custom Content Type.

I also need the same thing for Pages (WP_Uploads\Page\About_Us instead of WP_Uploads\2018\02\14) - but there are going to be much fewer of those.

  • 1
    You shouldn't need to worry about where an attachment is stored, especially since it could be used in multiple posts, so if the folder it's stored in is based on the post it's attached to you would run into problems if you use it in more than one place. Are you aware that you can view an attachment post with its own template on a pretty URL? e.g. tomjn.com/2017/08/31/where-gutenberg-leads-us/… vs tomjn.com/wp-content/uploads/2017/08/… ? attachment.php and in your theme – Tom J Nowell Apr 3 '18 at 16:09
  • You can even comment on attachments, the location of the file they represent inside the uploads folder is meant to be irrelevant – Tom J Nowell Apr 3 '18 at 16:10
0

You can start yout work with upload_dir filtering. However, I wouldn't recommend it (change this functionality). You will need to track few types of uploads and then track whoever is the parent of the upload. It's more complicated, then joyful task.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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