How does one bulk change the media attachment author via an sql query?

I have hundreds of media attachments that need to be moved to another author so the original author can be deleted; but that author has no posts, only media attachments.

(The images were attributed to the author when importing and running a query to take the first post image and make it a featured image.)

I think I need to specify the `post_type' in a query, like this:

update wp_posts and post_type = ‘attachment’


As answered below, this works UPDATE wp_posts SET post_author = [NEW_ID] WHERE post_author = [OLD_ID]

with or without the AND post_type = 'attachment'

1 Answer 1

UPDATE wp_posts SET post_author = [NEW_ID] WHERE post_author = [OLD_ID]
  • I don't need the change the post author; the post doesn't exist. I need to change the author of the media attachment. Mar 18, 2014 at 17:32
  • Please add an explanation to your answer: why could that solve the problem?
    – fuxia
    Mar 18, 2014 at 17:39
  • @songdogtech This will also work for media attachments, which are simply post objects in the database. Mar 18, 2014 at 18:08
  • @toscho How!? Doesn't get much simpler! Mar 18, 2014 at 18:08
  • @TheDeadMedic Explain that post_author is also an author of attachments. I found your post in our Low Quality queue; and such short posts are usually targets of spam edit suggestions.
    – fuxia
    Mar 18, 2014 at 18:24

Your Answer

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

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