I moved a bunch of Namine’s photo albums off to Picasa (which is now inside Google+, go figure). Now I had a bunch of photos to remove from WordPress, and there doesn’t seem to be any good way to remove all the pictures associated with a post or page.
Sure, the “Add Media” button allows you to select photos uploaded for a post, and even though you can select multiple photos, you can’t batch delete.
The media page wasn’t any better; it allowed me to sort pictures by the post they were uploaded for, but not group select. I still had to click, click, click my way through.
There must be a better way!
What ends up happening is really very simple. First, we’re getting all the listed links to a specific post. Next, the jQuery function closest() looks up the DOM tree for a first match. In this case, the parent table row. From there, we just need to find the image’s checkbox. There’s only one in each table row, so we don’t need to get any more precise than a simple find(). Lastly, we modify the “checked” property to “true.” And wah lah, we’ve just selected an obscene amount of checkboxes.
After that, all I had to do was hit “delete.” Done and done.