2

I've seen a couple of people ask about this but without a general conclusion.

It worked until recently, but recently all media uploads from the media upload tool end up in an old folder, 2019/10, instead of the one for the current month.

BUT when uploading from a new post, the media goes into the correct folder, for the current month.

So there's different behaviour between uploading from the media upload tool (the stock one), and when uploading from the post editor (the new / Gutenberg one, for blocks).

Any ideas where to start digging?

0

1 Answer 1

2

In case anyone encounters this in the future: after drilling down into the WP source and the database, it turns out that when media files are uploaded, WP still needs to attach them to some post, and for some reason, even though the post_id is 0 in the fuction which processes media uploads, it managed to find an entry in the wp_posts table and use that to attach media files to. After that, the mechanism which determins the path to save the media file based on the post it's attached to kicks in, so the file is saved in the folder of the post entry.

I solved this by deleting the entry in the wp_posts table, after which WP stopped attaching media uploads to post entries, and storing them in the folder structure based on the date of the upload (i.e. the current date).

This took instrumenting the WP source and drilling down into what happens in the database. Definitely seems like a bug, and definitely not solvable in a user-friendly way.

3
  • thanks for documenting the bug here. Can you say, what the issue with the post you had to delete was? I just realized I have the issued as the upload land in the folder /2021/03/ but I also have quite some since then...
    – wittich
    Jan 19 at 9:30
  • 1
    I'm not sure, this was kind of a brute force solution. Because I saw that uploads from the Media Manager end up attached to a specific entry in wp_posts, and because of that land in the specific date-stamped folder, I just deleted that particular wp_posts entry and it fixed my problem without breaking anything. I don't remember what that entry was, I don't think it was anything important.
    – Ivan Voras
    Jan 19 at 18:02
  • Thx for your reply. I debugged it a little too, and it is as you said, for some reason get_post( 0 ) returns a valid post, in my case $post_id = 8448 which has a $post_date from March 2021. I will dig further...
    – wittich
    Jan 19 at 22:49

Your Answer

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

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