Today I went to try and clean things up a little bit since I haven’t really done that in some time. At least it feels that way to me. I looked at the comments and realized there were some in the trash. I didn’t think much of it since you know it’s just trash.
There was one time where the comment was from a real person so that was also part of the reason I went and looked.
I saw there were quite a few being posted on images. I thought a little odd but not too crazy since those are to an extend considered posts. Or at least a post type. Yeah. About that.
So I wanted to see how I could just mass disable all of those without having to resort to a plugin because that’s always the solution, right? Not having to use a plugin is the best thing in the world. You would think.
Anyway.
So I set to figure out a filter and of course there was one. I didn’t want to go that route since I honestly wanted to try something a little different. So I tried to see if it could be done using a query. A database query to be a bit more exact.
The cool part was that I really was able to do that and for my site it really only took about less than a second to do. There were only about 75 or so media files that had an open setting. Well, attachments to be precise on that.
The reason I say “attachment” is because that’s how WordPress stores that information in the database. For those who may want to do the same, the query I ran was:
UPDATE wp_posts SET comment_status = "closed" WHERE post_type = 'attachment' AND comment_status = 'open';
The cool part was that it ran really quick since it was directly connecting to the database. The even better part was that I didn’t have to create a plugin for that though I think I may have to at one point down the line if I forget to change that setting when I upload another image.
I don’t know.
Creating a plugin may just be quicker down the line too. I just don’t want to do the maintaining thing I guess.